| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 8 #include "chrome/common/url_constants.h" | 8 #include "chrome/common/url_constants.h" |
| 9 #include "chrome/test/base/in_process_browser_test.h" | 9 #include "chrome/test/base/in_process_browser_test.h" |
| 10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| 11 #include "content/public/test/browser_test_utils.h" | 11 #include "content/public/test/browser_test_utils.h" |
| 12 #include "net/http/http_response_headers.h" | 12 #include "net/http/http_response_headers.h" |
| 13 #include "net/http/http_status_code.h" | 13 #include "net/http/http_status_code.h" |
| 14 #include "net/url_request/test_url_fetcher_factory.h" | 14 #include "net/url_request/test_url_fetcher_factory.h" |
| 15 #include "net/url_request/url_request_status.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 16 | 17 |
| 17 using ::testing::Exactly; | 18 using ::testing::Exactly; |
| 18 using ::testing::Invoke; | 19 using ::testing::Invoke; |
| 19 using ::testing::_; | 20 using ::testing::_; |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 const char kEULAURL[] = | 24 const char kEULAURL[] = |
| 24 "https://www.google.com/intl/en-US/chrome/eula_text.html"; | 25 "https://www.google.com/intl/en-US/chrome/eula_text.html"; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 53 fetcher->set_response_headers(download_headers); | 54 fetcher->set_response_headers(download_headers); |
| 54 } | 55 } |
| 55 | 56 |
| 56 // Load chrome://terms. Make sure online version is shown. | 57 // Load chrome://terms. Make sure online version is shown. |
| 57 IN_PROC_BROWSER_TEST_F(TermsOfServiceProcessBrowserTest, LoadOnline) { | 58 IN_PROC_BROWSER_TEST_F(TermsOfServiceProcessBrowserTest, LoadOnline) { |
| 58 TestURLFetcherCallback url_callback; | 59 TestURLFetcherCallback url_callback; |
| 59 net::FakeURLFetcherFactory factory( | 60 net::FakeURLFetcherFactory factory( |
| 60 NULL, | 61 NULL, |
| 61 base::Bind(&TestURLFetcherCallback::CreateURLFetcher, | 62 base::Bind(&TestURLFetcherCallback::CreateURLFetcher, |
| 62 base::Unretained(&url_callback))); | 63 base::Unretained(&url_callback))); |
| 63 factory.SetFakeResponse(GURL(kEULAURL), kFakeOnlineEULA, net::HTTP_OK); | 64 factory.SetFakeResponse(GURL(kEULAURL), kFakeOnlineEULA, |
| 65 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 64 EXPECT_CALL(url_callback, OnRequestCreate(GURL(kEULAURL), _)) | 66 EXPECT_CALL(url_callback, OnRequestCreate(GURL(kEULAURL), _)) |
| 65 .Times(Exactly(1)) | 67 .Times(Exactly(1)) |
| 66 .WillRepeatedly(Invoke(AddMimeHeader)); | 68 .WillRepeatedly(Invoke(AddMimeHeader)); |
| 67 | 69 |
| 68 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUITermsURL)); | 70 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUITermsURL)); |
| 69 content::WebContents* web_contents = | 71 content::WebContents* web_contents = |
| 70 browser()->tab_strip_model()->GetActiveWebContents(); | 72 browser()->tab_strip_model()->GetActiveWebContents(); |
| 71 EXPECT_EQ(1, ui_test_utils::FindInPage(web_contents, | 73 EXPECT_EQ(1, ui_test_utils::FindInPage(web_contents, |
| 72 ASCIIToUTF16(kFakeOnlineEULA), | 74 ASCIIToUTF16(kFakeOnlineEULA), |
| 73 true, | 75 true, |
| 74 true, | 76 true, |
| 75 NULL, | 77 NULL, |
| 76 NULL)); | 78 NULL)); |
| 77 } | 79 } |
| 78 | 80 |
| 79 // Load chrome://terms with no internet connectivity. | 81 // Load chrome://terms with no internet connectivity. |
| 80 // Make sure offline version is shown. | 82 // Make sure offline version is shown. |
| 81 IN_PROC_BROWSER_TEST_F(TermsOfServiceProcessBrowserTest, LoadOffline) { | 83 IN_PROC_BROWSER_TEST_F(TermsOfServiceProcessBrowserTest, LoadOffline) { |
| 82 net::FakeURLFetcherFactory factory(NULL); | 84 net::FakeURLFetcherFactory factory(NULL); |
| 83 factory.SetFakeResponse(GURL(kEULAURL), "", net::HTTP_INTERNAL_SERVER_ERROR); | 85 factory.SetFakeResponse(GURL(kEULAURL), "", net::HTTP_INTERNAL_SERVER_ERROR, |
| 86 net::URLRequestStatus::FAILED); |
| 84 | 87 |
| 85 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUITermsURL)); | 88 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUITermsURL)); |
| 86 content::WebContents* web_contents = | 89 content::WebContents* web_contents = |
| 87 browser()->tab_strip_model()->GetActiveWebContents(); | 90 browser()->tab_strip_model()->GetActiveWebContents(); |
| 88 | 91 |
| 89 #if defined(GOOGLE_CHROME_BUILD) | 92 #if defined(GOOGLE_CHROME_BUILD) |
| 90 EXPECT_NE(0, ui_test_utils::FindInPage(web_contents, | 93 EXPECT_NE(0, ui_test_utils::FindInPage(web_contents, |
| 91 ASCIIToUTF16(kOfflineEULAWarning), | 94 ASCIIToUTF16(kOfflineEULAWarning), |
| 92 true, | 95 true, |
| 93 true, | 96 true, |
| 94 NULL, | 97 NULL, |
| 95 NULL)); | 98 NULL)); |
| 96 #else | 99 #else |
| 97 std::string body; | 100 std::string body; |
| 98 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 101 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 99 web_contents, | 102 web_contents, |
| 100 "window.domAutomationController.send(document.body.textContent)", | 103 "window.domAutomationController.send(document.body.textContent)", |
| 101 &body)); | 104 &body)); |
| 102 EXPECT_NE(std::string(), body); | 105 EXPECT_NE(std::string(), body); |
| 103 #endif | 106 #endif |
| 104 } | 107 } |
| 105 | 108 |
| 106 } // namespace | 109 } // namespace |
| OLD | NEW |