Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: chrome/browser/chromeos/login/eula_browsertest.cc

Issue 14746014: CrOS EULA: added 2 browser tests (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix EULA URL Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/webui/about_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/tabs/tab_strip_model.h"
8 #include "chrome/common/url_constants.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/public/test/browser_test_utils.h"
12 #include "net/http/http_response_headers.h"
13 #include "net/url_request/test_url_fetcher_factory.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15
16 using ::testing::Exactly;
17 using ::testing::Invoke;
18 using ::testing::_;
19
20 namespace {
21
22 const char kEULAURL[] = "https://www.google.com/intl/en-US/chrome/eula_text.html ";
23 const char kFakeOnlineEULA[] = "No obligations at all";
24 const char kOfflineEULAWarning[] = "A copy of the Google Terms of Service";
25
26 class TermsOfServiceProcessBrowserTest : public InProcessBrowserTest {
27 };
28
29 class TestURLFetcherCallback {
30 public:
31 scoped_ptr<net::FakeURLFetcher> CreateURLFetcher(
32 const GURL& url,
33 net::URLFetcherDelegate* d,
34 const std::string& response_data,
35 bool success) {
36 scoped_ptr<net::FakeURLFetcher> fetcher(
37 new net::FakeURLFetcher(url, d, response_data, success));
38 OnRequestCreate(url, fetcher.get());
39 return fetcher.Pass();
40 }
41 MOCK_METHOD2(OnRequestCreate,
42 void(const GURL&, net::FakeURLFetcher*));
43 };
44
45 void AddMimeHeader(const GURL& url, net::FakeURLFetcher* fetcher) {
46 scoped_refptr<net::HttpResponseHeaders> download_headers =
47 new net::HttpResponseHeaders("");
48 download_headers->AddHeader("Content-Type: text/html");
49 fetcher->set_response_headers(download_headers);
50 }
51
52 // Load chrome://terms. Make sure online version is shown.
53 IN_PROC_BROWSER_TEST_F(TermsOfServiceProcessBrowserTest, LoadOnline) {
54 TestURLFetcherCallback url_callback;
55 net::FakeURLFetcherFactory factory(
56 NULL,
57 base::Bind(&TestURLFetcherCallback::CreateURLFetcher,
58 base::Unretained(&url_callback)));
59 factory.SetFakeResponse(kEULAURL, kFakeOnlineEULA, true);
60 EXPECT_CALL(url_callback, OnRequestCreate(GURL(kEULAURL), _))
61 .Times(Exactly(1))
62 .WillRepeatedly(Invoke(AddMimeHeader));
63
64 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUITermsURL));
65 content::WebContents* web_contents =
66 browser()->tab_strip_model()->GetActiveWebContents();
67 EXPECT_EQ(1, ui_test_utils::FindInPage(web_contents,
68 ASCIIToUTF16(kFakeOnlineEULA),
69 true,
70 true,
71 NULL,
72 NULL));
73 }
74
75 // Load chrome://terms with no internet connectivity.
76 // Make sure offline version is shown.
77 IN_PROC_BROWSER_TEST_F(TermsOfServiceProcessBrowserTest, LoadOffline) {
78 net::FakeURLFetcherFactory factory(NULL);
79 factory.SetFakeResponse(kEULAURL, "", false);
80
81 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUITermsURL));
82 content::WebContents* web_contents =
83 browser()->tab_strip_model()->GetActiveWebContents();
84
85 #if defined(GOOGLE_CHROME_BUILD)
86 EXPECT_NE(0, ui_test_utils::FindInPage(web_contents,
87 ASCIIToUTF16(kOfflineEULAWarning),
88 true,
89 true,
90 NULL,
91 NULL));
92 #else
93 std::string body;
94 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
95 web_contents,
96 "window.domAutomationController.send(document.body.textContent)",
97 &body));
98 EXPECT_NE(std::string(), body);
99 #endif
100 }
101
102 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/about_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698