OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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/guid.h" |
| 6 #include "base/strings/stringprintf.h" |
| 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "components/prefs/pref_service.h" |
| 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/test/browser_test_utils.h" |
| 16 #include "url/gurl.h" |
| 17 |
| 18 using PrefsInternalsTest = InProcessBrowserTest; |
| 19 |
| 20 IN_PROC_BROWSER_TEST_F(PrefsInternalsTest, TestPrefsAreServed) { |
| 21 // Set a preference to something very unique so we can look for it in the |
| 22 // generated page. |
| 23 std::string guid = base::GenerateGUID(); |
| 24 GURL fake_homepage_url = GURL("http://example.com/" + guid); |
| 25 EXPECT_TRUE(fake_homepage_url.is_valid()); |
| 26 browser()->profile()->GetPrefs()->SetString(prefs::kHomePage, |
| 27 fake_homepage_url.spec()); |
| 28 |
| 29 // First, check that navigation succeeds. |
| 30 GURL kUrl("chrome://prefs-internals"); |
| 31 ui_test_utils::NavigateToURL(browser(), kUrl); |
| 32 content::WebContents* web_contents = |
| 33 browser()->tab_strip_model()->GetActiveWebContents(); |
| 34 ASSERT_TRUE(web_contents); |
| 35 EXPECT_EQ(kUrl, web_contents->GetLastCommittedURL()); |
| 36 EXPECT_FALSE(web_contents->IsCrashed()); |
| 37 EXPECT_FALSE(web_contents->GetInterstitialPage()); |
| 38 |
| 39 // It's difficult to test the content of the page without duplicating the |
| 40 // implementation, but we can at least assert that something is being shown. |
| 41 bool has_text = false; |
| 42 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 43 web_contents, |
| 44 base::StringPrintf("window.domAutomationController.send(" |
| 45 "document.body.textContent && " |
| 46 "document.body.textContent.indexOf('%s') >= 0);", |
| 47 guid.c_str()), |
| 48 &has_text)); |
| 49 EXPECT_TRUE(has_text); |
| 50 } |
OLD | NEW |