| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "content/public/browser/notification_types.h" | 49 #include "content/public/browser/notification_types.h" |
| 50 #include "content/public/browser/page_navigator.h" | 50 #include "content/public/browser/page_navigator.h" |
| 51 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" |
| 52 #include "content/public/browser/web_contents_delegate.h" | 52 #include "content/public/browser/web_contents_delegate.h" |
| 53 #include "content/public/common/content_switches.h" | 53 #include "content/public/common/content_switches.h" |
| 54 #include "content/public/common/referrer.h" | 54 #include "content/public/common/referrer.h" |
| 55 #include "content/public/common/url_constants.h" | 55 #include "content/public/common/url_constants.h" |
| 56 #include "content/public/test/browser_test_utils.h" | 56 #include "content/public/test/browser_test_utils.h" |
| 57 #include "content/public/test/test_utils.h" | 57 #include "content/public/test/test_utils.h" |
| 58 #include "google_apis/gaia/google_service_auth_error.h" | 58 #include "google_apis/gaia/google_service_auth_error.h" |
| 59 #include "net/test/spawned_test_server/spawned_test_server.h" | 59 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 60 #include "testing/gmock/include/gmock/gmock.h" | 60 #include "testing/gmock/include/gmock/gmock.h" |
| 61 #include "testing/gtest/include/gtest/gtest.h" | 61 #include "testing/gtest/include/gtest/gtest.h" |
| 62 #include "third_party/WebKit/public/web/WebInputEvent.h" | 62 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 63 #include "ui/base/page_transition_types.h" | 63 #include "ui/base/page_transition_types.h" |
| 64 #include "ui/base/window_open_disposition.h" | 64 #include "ui/base/window_open_disposition.h" |
| 65 #include "url/gurl.h" | 65 #include "url/gurl.h" |
| 66 | 66 |
| 67 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
| 68 #include "base/win/windows_version.h" | 68 #include "base/win/windows_version.h" |
| 69 #elif defined(OS_MACOSX) | 69 #elif defined(OS_MACOSX) |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 387 |
| 388 InitiateDialog(); | 388 InitiateDialog(); |
| 389 AutofillDialogControllerImpl* controller = | 389 AutofillDialogControllerImpl* controller = |
| 390 static_cast<AutofillDialogControllerImpl*>( | 390 static_cast<AutofillDialogControllerImpl*>( |
| 391 client->GetDialogControllerForTesting()); | 391 client->GetDialogControllerForTesting()); |
| 392 return controller; | 392 return controller; |
| 393 } | 393 } |
| 394 | 394 |
| 395 // Loads an html page on a provided server, the causes it to launch rAc. | 395 // Loads an html page on a provided server, the causes it to launch rAc. |
| 396 // Returns whether rAc succesfully launched. | 396 // Returns whether rAc succesfully launched. |
| 397 bool RunTestPage(const net::SpawnedTestServer& server) { | 397 bool RunTestPage(const net::EmbeddedTestServer& server) { |
| 398 GURL url = server.GetURL( | 398 GURL url = server.GetURL("/request_autocomplete/test_page.html"); |
| 399 "files/request_autocomplete/test_page.html"); | |
| 400 ui_test_utils::NavigateToURL(browser(), url); | 399 ui_test_utils::NavigateToURL(browser(), url); |
| 401 | 400 |
| 402 // Pass through the broken SSL interstitial, if any. | 401 // Pass through the broken SSL interstitial, if any. |
| 403 content::WebContents* contents = GetActiveWebContents(); | 402 content::WebContents* contents = GetActiveWebContents(); |
| 404 content::InterstitialPage* interstitial_page = | 403 content::InterstitialPage* interstitial_page = |
| 405 contents->GetInterstitialPage(); | 404 contents->GetInterstitialPage(); |
| 406 if (interstitial_page) { | 405 if (interstitial_page) { |
| 407 ui_test_utils::UrlLoadObserver observer( | 406 ui_test_utils::UrlLoadObserver observer( |
| 408 url, | 407 url, |
| 409 content::Source<content::NavigationController>( | 408 content::Source<content::NavigationController>( |
| 410 &contents->GetController())); | 409 &contents->GetController())); |
| 411 interstitial_page->Proceed(); | 410 interstitial_page->Proceed(); |
| 412 observer.Wait(); | 411 observer.Wait(); |
| 413 } | 412 } |
| 414 | 413 |
| 415 InitiateDialog(); | 414 InitiateDialog(); |
| 416 | 415 |
| 417 ChromeAutofillClient* client = | 416 ChromeAutofillClient* client = |
| 418 ChromeAutofillClient::FromWebContents(contents); | 417 ChromeAutofillClient::FromWebContents(contents); |
| 419 AutofillDialogControllerImpl* controller = | 418 AutofillDialogControllerImpl* controller = |
| 420 static_cast<AutofillDialogControllerImpl*>( | 419 static_cast<AutofillDialogControllerImpl*>( |
| 421 client->GetDialogControllerForTesting()); | 420 client->GetDialogControllerForTesting()); |
| 422 return !!controller; | 421 return !!controller; |
| 423 } | 422 } |
| 424 | 423 |
| 425 void RunTestPageInIframe(const net::SpawnedTestServer& server) { | 424 void RunTestPageInIframe(const net::EmbeddedTestServer& server) { |
| 426 InitializeDOMMessageQueue(); | 425 InitializeDOMMessageQueue(); |
| 427 GURL iframe_url = server.GetURL( | 426 GURL iframe_url = server.GetURL("/request_autocomplete/test_page.html"); |
| 428 "files/request_autocomplete/test_page.html"); | |
| 429 | 427 |
| 430 ui_test_utils::NavigateToURL( | 428 ui_test_utils::NavigateToURL( |
| 431 browser(), GURL(std::string("data:text/html,") + | 429 browser(), GURL(std::string("data:text/html,") + |
| 432 "<!doctype html>" | 430 "<!doctype html>" |
| 433 "<html>" | 431 "<html>" |
| 434 "<body>" | 432 "<body>" |
| 435 "<iframe style='position: fixed;" | 433 "<iframe style='position: fixed;" |
| 436 "height: 100%;" | 434 "height: 100%;" |
| 437 "width: 100%;'" | 435 "width: 100%;'" |
| 438 "id='racFrame'></iframe>" | 436 "id='racFrame'></iframe>" |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 // Tabs should now be: / rAc() \/ manage 2 \/ manage 1 \/ blank \. | 1073 // Tabs should now be: / rAc() \/ manage 2 \/ manage 1 \/ blank \. |
| 1076 EXPECT_EQ(4, tab_strip->count()); | 1074 EXPECT_EQ(4, tab_strip->count()); |
| 1077 EXPECT_EQ(0, tab_strip->GetIndexOfWebContents(dialog_invoker)); | 1075 EXPECT_EQ(0, tab_strip->GetIndexOfWebContents(dialog_invoker)); |
| 1078 EXPECT_EQ(1, tab_strip->active_index()); | 1076 EXPECT_EQ(1, tab_strip->active_index()); |
| 1079 EXPECT_EQ(2, tab_strip->GetIndexOfWebContents(first_manage_tab)); | 1077 EXPECT_EQ(2, tab_strip->GetIndexOfWebContents(first_manage_tab)); |
| 1080 EXPECT_EQ(3, tab_strip->GetIndexOfWebContents(blank_tab)); | 1078 EXPECT_EQ(3, tab_strip->GetIndexOfWebContents(blank_tab)); |
| 1081 } | 1079 } |
| 1082 | 1080 |
| 1083 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | 1081 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
| 1084 DoesWorkOnHttpWithFlag) { | 1082 DoesWorkOnHttpWithFlag) { |
| 1085 net::SpawnedTestServer http_server( | 1083 net::EmbeddedTestServer http_server; |
| 1086 net::SpawnedTestServer::TYPE_HTTP, | 1084 http_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 1087 net::SpawnedTestServer::kLocalhost, | |
| 1088 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 1089 ASSERT_TRUE(http_server.Start()); | 1085 ASSERT_TRUE(http_server.Start()); |
| 1090 EXPECT_TRUE(RunTestPage(http_server)); | 1086 EXPECT_TRUE(RunTestPage(http_server)); |
| 1091 } | 1087 } |
| 1092 | 1088 |
| 1093 // Like the parent test, but doesn't add the --reduce-security-for-testing flag. | 1089 // Like the parent test, but doesn't add the --reduce-security-for-testing flag. |
| 1094 class AutofillDialogControllerSecurityTest : | 1090 class AutofillDialogControllerSecurityTest : |
| 1095 public AutofillDialogControllerTest { | 1091 public AutofillDialogControllerTest { |
| 1096 public: | 1092 public: |
| 1097 AutofillDialogControllerSecurityTest() {} | 1093 AutofillDialogControllerSecurityTest() {} |
| 1098 ~AutofillDialogControllerSecurityTest() override {} | 1094 ~AutofillDialogControllerSecurityTest() override {} |
| 1099 | 1095 |
| 1100 void SetUpCommandLine(base::CommandLine* command_line) override { | 1096 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 1101 CHECK(!command_line->HasSwitch(::switches::kReduceSecurityForTesting)); | 1097 CHECK(!command_line->HasSwitch(::switches::kReduceSecurityForTesting)); |
| 1102 } | 1098 } |
| 1103 | 1099 |
| 1104 typedef net::BaseTestServer::SSLOptions SSLOptions; | 1100 typedef net::BaseTestServer::SSLOptions SSLOptions; |
| 1105 | 1101 |
| 1106 private: | 1102 private: |
| 1107 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerSecurityTest); | 1103 DISALLOW_COPY_AND_ASSIGN(AutofillDialogControllerSecurityTest); |
| 1108 }; | 1104 }; |
| 1109 | 1105 |
| 1110 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerSecurityTest, | 1106 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerSecurityTest, |
| 1111 DoesntWorkOnHttp) { | 1107 DoesntWorkOnHttp) { |
| 1112 net::SpawnedTestServer http_server( | 1108 net::EmbeddedTestServer http_server; |
| 1113 net::SpawnedTestServer::TYPE_HTTP, | 1109 http_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 1114 net::SpawnedTestServer::kLocalhost, | |
| 1115 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 1116 ASSERT_TRUE(http_server.Start()); | 1110 ASSERT_TRUE(http_server.Start()); |
| 1117 EXPECT_FALSE(RunTestPage(http_server)); | 1111 EXPECT_FALSE(RunTestPage(http_server)); |
| 1118 } | 1112 } |
| 1119 | 1113 |
| 1120 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerSecurityTest, | 1114 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerSecurityTest, |
| 1121 DoesWorkOnHttpWithFlags) { | 1115 DoesWorkOnHttpWithFlags) { |
| 1122 net::SpawnedTestServer https_server( | 1116 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 1123 net::SpawnedTestServer::TYPE_HTTPS, | 1117 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 1124 SSLOptions(SSLOptions::CERT_OK), | |
| 1125 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 1126 ASSERT_TRUE(https_server.Start()); | 1118 ASSERT_TRUE(https_server.Start()); |
| 1127 EXPECT_TRUE(RunTestPage(https_server)); | 1119 EXPECT_TRUE(RunTestPage(https_server)); |
| 1128 } | 1120 } |
| 1129 | 1121 |
| 1130 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerSecurityTest, | 1122 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerSecurityTest, |
| 1131 DISABLED_DoesntWorkOnBrokenHttps) { | 1123 DISABLED_DoesntWorkOnBrokenHttps) { |
| 1132 net::SpawnedTestServer https_server( | 1124 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 1133 net::SpawnedTestServer::TYPE_HTTPS, | 1125 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 1134 SSLOptions(SSLOptions::CERT_EXPIRED), | |
| 1135 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 1136 ASSERT_TRUE(https_server.Start()); | 1126 ASSERT_TRUE(https_server.Start()); |
| 1137 EXPECT_FALSE(RunTestPage(https_server)); | 1127 EXPECT_FALSE(RunTestPage(https_server)); |
| 1138 } | 1128 } |
| 1139 | 1129 |
| 1140 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, | 1130 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, |
| 1141 CountryChangeRebuildsSection) { | 1131 CountryChangeRebuildsSection) { |
| 1142 EXPECT_FALSE(SectionHasField(SECTION_BILLING, ADDRESS_BILLING_SORTING_CODE)); | 1132 EXPECT_FALSE(SectionHasField(SECTION_BILLING, ADDRESS_BILLING_SORTING_CODE)); |
| 1143 EXPECT_FALSE(SectionHasField(SECTION_SHIPPING, ADDRESS_HOME_SORTING_CODE)); | 1133 EXPECT_FALSE(SectionHasField(SECTION_SHIPPING, ADDRESS_HOME_SORTING_CODE)); |
| 1144 | 1134 |
| 1145 // Select "Add new shipping address...". | 1135 // Select "Add new shipping address...". |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 controller()->AsWeakPtr(); | 1301 controller()->AsWeakPtr(); |
| 1312 EXPECT_TRUE(weak_ptr.get()); | 1302 EXPECT_TRUE(weak_ptr.get()); |
| 1313 | 1303 |
| 1314 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 1304 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 1315 EXPECT_FALSE(weak_ptr.get()); | 1305 EXPECT_FALSE(weak_ptr.get()); |
| 1316 } | 1306 } |
| 1317 | 1307 |
| 1318 // Tests that the rAc dialog hides when the main frame is navigated, even if | 1308 // Tests that the rAc dialog hides when the main frame is navigated, even if |
| 1319 // it was invoked from a child frame. | 1309 // it was invoked from a child frame. |
| 1320 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigateMainFrame) { | 1310 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigateMainFrame) { |
| 1321 net::SpawnedTestServer http_server( | 1311 net::EmbeddedTestServer http_server; |
| 1322 net::SpawnedTestServer::TYPE_HTTP, | 1312 http_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 1323 net::SpawnedTestServer::kLocalhost, | |
| 1324 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 1325 ASSERT_TRUE(http_server.Start()); | 1313 ASSERT_TRUE(http_server.Start()); |
| 1326 RunTestPageInIframe(http_server); | 1314 RunTestPageInIframe(http_server); |
| 1327 | 1315 |
| 1328 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); | 1316 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 1329 ChromeAutofillClient* client = | 1317 ChromeAutofillClient* client = |
| 1330 ChromeAutofillClient::FromWebContents(GetActiveWebContents()); | 1318 ChromeAutofillClient::FromWebContents(GetActiveWebContents()); |
| 1331 EXPECT_FALSE(client->GetDialogControllerForTesting()); | 1319 EXPECT_FALSE(client->GetDialogControllerForTesting()); |
| 1332 } | 1320 } |
| 1333 | 1321 |
| 1334 // Tests that the rAc dialog hides when the iframe it's in is navigated. | 1322 // Tests that the rAc dialog hides when the iframe it's in is navigated. |
| 1335 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigateIframe) { | 1323 IN_PROC_BROWSER_TEST_F(AutofillDialogControllerTest, HideOnNavigateIframe) { |
| 1336 net::SpawnedTestServer http_server( | 1324 net::EmbeddedTestServer http_server; |
| 1337 net::SpawnedTestServer::TYPE_HTTP, | 1325 http_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 1338 net::SpawnedTestServer::kLocalhost, | |
| 1339 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 1340 ASSERT_TRUE(http_server.Start()); | 1326 ASSERT_TRUE(http_server.Start()); |
| 1341 RunTestPageInIframe(http_server); | 1327 RunTestPageInIframe(http_server); |
| 1342 | 1328 |
| 1343 std::string unused; | 1329 std::string unused; |
| 1344 ASSERT_TRUE(content::ExecuteScriptAndExtractString(GetRenderViewHost(), | 1330 ASSERT_TRUE(content::ExecuteScriptAndExtractString(GetRenderViewHost(), |
| 1345 "navigateFrame();", | 1331 "navigateFrame();", |
| 1346 &unused)); | 1332 &unused)); |
| 1347 ExpectDomMessage("iframe loaded"); | 1333 ExpectDomMessage("iframe loaded"); |
| 1348 ChromeAutofillClient* client = | 1334 ChromeAutofillClient* client = |
| 1349 ChromeAutofillClient::FromWebContents(GetActiveWebContents()); | 1335 ChromeAutofillClient::FromWebContents(GetActiveWebContents()); |
| 1350 EXPECT_FALSE(client->GetDialogControllerForTesting()); | 1336 EXPECT_FALSE(client->GetDialogControllerForTesting()); |
| 1351 } | 1337 } |
| 1352 | 1338 |
| 1353 } // namespace autofill | 1339 } // namespace autofill |
| OLD | NEW |