| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 | 592 |
| 593 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 593 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 594 CommandLine::ForCurrentProcess()->AppendSwitch("noerrdialogs"); | 594 CommandLine::ForCurrentProcess()->AppendSwitch("noerrdialogs"); |
| 595 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 595 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 596 .WillRepeatedly(Return(true)); | 596 .WillRepeatedly(Return(true)); |
| 597 EXPECT_CALL(provider_, RegisterPolicyDomain(_)).Times(AnyNumber()); | 597 EXPECT_CALL(provider_, RegisterPolicyDomain(_)).Times(AnyNumber()); |
| 598 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 598 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 599 } | 599 } |
| 600 | 600 |
| 601 virtual void SetUpOnMainThread() OVERRIDE { | 601 virtual void SetUpOnMainThread() OVERRIDE { |
| 602 // Wait for the InstantNTP prerendered contents to load. |
| 603 content::WindowedNotificationObserver observer( |
| 604 content::NOTIFICATION_LOAD_STOP, |
| 605 content::NotificationService::AllSources()); |
| 606 observer.Wait(); |
| 602 BrowserThread::PostTask( | 607 BrowserThread::PostTask( |
| 603 BrowserThread::IO, FROM_HERE, | 608 BrowserThread::IO, FROM_HERE, |
| 604 base::Bind(chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 609 base::Bind(chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
| 605 } | 610 } |
| 606 | 611 |
| 607 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA | 612 // Makes URLRequestMockHTTPJobs serve data from content::DIR_TEST_DATA |
| 608 // instead of chrome::DIR_TEST_DATA. | 613 // instead of chrome::DIR_TEST_DATA. |
| 609 void ServeContentTestData() { | 614 void ServeContentTestData() { |
| 610 base::FilePath root_http; | 615 base::FilePath root_http; |
| 611 PathService::Get(content::DIR_TEST_DATA, &root_http); | 616 PathService::Get(content::DIR_TEST_DATA, &root_http); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 | 784 |
| 780 PolicyMap policies; | 785 PolicyMap policies; |
| 781 policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY, | 786 policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY, |
| 782 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true), NULL); | 787 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true), NULL); |
| 783 UpdateProviderPolicy(policies); | 788 UpdateProviderPolicy(policies); |
| 784 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); | 789 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); |
| 785 EXPECT_TRUE(prefs->GetBoolean(prefs::kShowBookmarkBar)); | 790 EXPECT_TRUE(prefs->GetBoolean(prefs::kShowBookmarkBar)); |
| 786 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); | 791 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); |
| 787 | 792 |
| 788 // The NTP has special handling of the bookmark bar. | 793 // The NTP has special handling of the bookmark bar. |
| 789 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); | 794 ui_test_utils::NavigateToURLWithDisposition( |
| 795 browser(), GURL(chrome::kChromeUINewTabURL), CURRENT_TAB, |
| 796 ui_test_utils::BROWSER_TEST_NONE); |
| 790 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); | 797 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); |
| 791 | 798 |
| 792 policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY, | 799 policies.Set(key::kBookmarkBarEnabled, POLICY_LEVEL_MANDATORY, |
| 793 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false), NULL); | 800 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false), NULL); |
| 794 UpdateProviderPolicy(policies); | 801 UpdateProviderPolicy(policies); |
| 795 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); | 802 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kShowBookmarkBar)); |
| 796 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowBookmarkBar)); | 803 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowBookmarkBar)); |
| 797 // The bookmark bar is hidden in the NTP when disabled by policy. | 804 // The bookmark bar is hidden in the NTP when disabled by policy. |
| 798 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); | 805 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); |
| 799 | 806 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 std::string expected_url("http://google.com/?"); | 996 std::string expected_url("http://google.com/?"); |
| 990 expected_url += std::string(chrome::kSafeSearchSafeParameter) + "&" + | 997 expected_url += std::string(chrome::kSafeSearchSafeParameter) + "&" + |
| 991 chrome::kSafeSearchSsuiParameter; | 998 chrome::kSafeSearchSsuiParameter; |
| 992 GURL expected_with_parameters(expected_url); | 999 GURL expected_with_parameters(expected_url); |
| 993 EXPECT_EQ(expected_with_parameters, web_contents->GetURL()); | 1000 EXPECT_EQ(expected_with_parameters, web_contents->GetURL()); |
| 994 } | 1001 } |
| 995 | 1002 |
| 996 IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) { | 1003 IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) { |
| 997 MakeRequestFail make_request_fail("search.example"); | 1004 MakeRequestFail make_request_fail("search.example"); |
| 998 | 1005 |
| 999 chrome::EnableInstantExtendedAPIForTesting(); | 1006 chrome::EnableQueryExtractionForTesting(); |
| 1000 | 1007 |
| 1001 // Verifies that a default search is made using the provider configured via | 1008 // Verifies that a default search is made using the provider configured via |
| 1002 // policy. Also checks that default search can be completely disabled. | 1009 // policy. Also checks that default search can be completely disabled. |
| 1003 const string16 kKeyword(ASCIIToUTF16("testsearch")); | 1010 const string16 kKeyword(ASCIIToUTF16("testsearch")); |
| 1004 const std::string kSearchURL("https://www.google.com/search?q={searchTerms}"); | 1011 const std::string kSearchURL("https://www.google.com/search?q={searchTerms}"); |
| 1005 const std::string kInstantURL("http://does/not/exist"); | 1012 const std::string kInstantURL("http://does/not/exist"); |
| 1006 const std::string kAlternateURL0( | 1013 const std::string kAlternateURL0( |
| 1007 "https://www.google.com/search#q={searchTerms}"); | 1014 "https://www.google.com/search#q={searchTerms}"); |
| 1008 const std::string kAlternateURL1("https://www.google.com/#q={searchTerms}"); | 1015 const std::string kAlternateURL1("https://www.google.com/#q={searchTerms}"); |
| 1009 const std::string kSearchTermsReplacementKey( | 1016 const std::string kSearchTermsReplacementKey( |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 policies.Set(key::kDeveloperToolsDisabled, POLICY_LEVEL_MANDATORY, | 1329 policies.Set(key::kDeveloperToolsDisabled, POLICY_LEVEL_MANDATORY, |
| 1323 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true), NULL); | 1330 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true), NULL); |
| 1324 UpdateProviderPolicy(policies); | 1331 UpdateProviderPolicy(policies); |
| 1325 // The existing devtools window should have closed. | 1332 // The existing devtools window should have closed. |
| 1326 EXPECT_FALSE(DevToolsWindow::GetDockedInstanceForInspectedTab(contents)); | 1333 EXPECT_FALSE(DevToolsWindow::GetDockedInstanceForInspectedTab(contents)); |
| 1327 // And it's not possible to open it again. | 1334 // And it's not possible to open it again. |
| 1328 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); | 1335 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); |
| 1329 EXPECT_FALSE(DevToolsWindow::GetDockedInstanceForInspectedTab(contents)); | 1336 EXPECT_FALSE(DevToolsWindow::GetDockedInstanceForInspectedTab(contents)); |
| 1330 } | 1337 } |
| 1331 | 1338 |
| 1332 IN_PROC_BROWSER_TEST_F(PolicyTest, WebStoreIconHidden) { | 1339 // TODO(samarth): remove along with the NTP4 code. |
| 1340 IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_WebStoreIconHidden) { |
| 1333 #if defined(OS_WIN) && defined(USE_ASH) | 1341 #if defined(OS_WIN) && defined(USE_ASH) |
| 1334 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 1342 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 1335 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 1343 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| 1336 return; | 1344 return; |
| 1337 #endif | 1345 #endif |
| 1338 | 1346 |
| 1339 // Verifies that the web store icons can be hidden from the new tab page. | 1347 // Verifies that the web store icons can be hidden from the new tab page. |
| 1340 | 1348 |
| 1341 // Open new tab page and look for the web store icons. | 1349 // Open new tab page and look for the web store icons. |
| 1342 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); | 1350 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
| (...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2397 #if defined(OS_WIN) && defined(USE_ASH) | 2405 #if defined(OS_WIN) && defined(USE_ASH) |
| 2398 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 2406 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 2399 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 2407 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| 2400 return; | 2408 return; |
| 2401 #endif | 2409 #endif |
| 2402 | 2410 |
| 2403 TabStripModel* model = browser()->tab_strip_model(); | 2411 TabStripModel* model = browser()->tab_strip_model(); |
| 2404 int size = static_cast<int>(expected_urls_.size()); | 2412 int size = static_cast<int>(expected_urls_.size()); |
| 2405 EXPECT_EQ(size, model->count()); | 2413 EXPECT_EQ(size, model->count()); |
| 2406 for (int i = 0; i < size && i < model->count(); ++i) { | 2414 for (int i = 0; i < size && i < model->count(); ++i) { |
| 2407 EXPECT_EQ(expected_urls_[i], model->GetWebContentsAt(i)->GetURL()); | 2415 if (expected_urls_[i] == GURL(chrome::kChromeUINewTabURL)) { |
| 2416 EXPECT_TRUE(chrome::IsNTPURL(model->GetWebContentsAt(i)->GetURL(), |
| 2417 browser()->profile())); |
| 2418 } else { |
| 2419 EXPECT_EQ(expected_urls_[i], model->GetWebContentsAt(i)->GetURL()); |
| 2420 } |
| 2408 } | 2421 } |
| 2409 } | 2422 } |
| 2410 | 2423 |
| 2411 INSTANTIATE_TEST_CASE_P( | 2424 INSTANTIATE_TEST_CASE_P( |
| 2412 RestoreOnStartupPolicyTestInstance, | 2425 RestoreOnStartupPolicyTestInstance, |
| 2413 RestoreOnStartupPolicyTest, | 2426 RestoreOnStartupPolicyTest, |
| 2414 testing::Values(&RestoreOnStartupPolicyTest::HomepageIsNotNTP, | 2427 testing::Values(&RestoreOnStartupPolicyTest::HomepageIsNotNTP, |
| 2415 &RestoreOnStartupPolicyTest::HomepageIsNTP, | 2428 &RestoreOnStartupPolicyTest::HomepageIsNTP, |
| 2416 &RestoreOnStartupPolicyTest::ListOfURLs, | 2429 &RestoreOnStartupPolicyTest::ListOfURLs, |
| 2417 &RestoreOnStartupPolicyTest::NTP, | 2430 &RestoreOnStartupPolicyTest::NTP, |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2727 chrome_variations::VariationsService::GetVariationsServerURL( | 2740 chrome_variations::VariationsService::GetVariationsServerURL( |
| 2728 g_browser_process->local_state()); | 2741 g_browser_process->local_state()); |
| 2729 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); | 2742 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); |
| 2730 std::string value; | 2743 std::string value; |
| 2731 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 2744 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
| 2732 EXPECT_EQ("restricted", value); | 2745 EXPECT_EQ("restricted", value); |
| 2733 } | 2746 } |
| 2734 #endif | 2747 #endif |
| 2735 | 2748 |
| 2736 } // namespace policy | 2749 } // namespace policy |
| OLD | NEW |