Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
|
dominickn
2017/03/29 07:46:33
2017 for a new file? :)
| |
| 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/command_line.h" | |
| 6 #include "chrome/browser/engagement/site_engagement_service.h" | |
| 7 #include "chrome/browser/ui/browser.h" | |
| 8 #include "chrome/browser/ui/browser_commands.h" | |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 10 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | |
| 11 #include "chrome/common/url_constants.h" | |
| 12 #include "chrome/test/base/in_process_browser_test.h" | |
| 13 #include "chrome/test/base/ui_test_utils.h" | |
| 14 #include "content/public/browser/child_process_security_policy.h" | |
| 15 #include "content/public/browser/render_process_host.h" | |
| 16 #include "content/public/common/content_switches.h" | |
| 17 #include "content/public/test/browser_test_utils.h" | |
| 18 #include "content/public/test/test_utils.h" | |
| 19 | |
| 20 using SiteEngagementUiBrowserTest = InProcessBrowserTest; | |
| 21 | |
| 22 IN_PROC_BROWSER_TEST_F(SiteEngagementUiBrowserTest, Basic) { | |
| 23 // Fake some activity to populate site engagement scores. | |
| 24 SiteEngagementService* service = | |
| 25 SiteEngagementService::Get(browser()->profile()); | |
| 26 | |
| 27 const GURL kExampleUrl = GURL("http://www.example.com/"); | |
| 28 service->ResetBaseScoreForURL(kExampleUrl, service->GetMaxPoints()); | |
| 29 | |
| 30 // Navigate a tab to the site engagement WebUI. | |
| 31 content::WebContents* web_contents = | |
| 32 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 33 | |
| 34 const GURL web_ui_url(std::string(content::kChromeUIScheme) + "://" + | |
| 35 std::string(chrome::kChromeUISiteEngagementHost)); | |
| 36 EXPECT_TRUE(ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( | |
| 37 web_contents->GetBrowserContext(), web_ui_url)); | |
| 38 ui_test_utils::NavigateToURL(browser(), web_ui_url); | |
| 39 EXPECT_TRUE( | |
| 40 content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( | |
| 41 web_contents->GetRenderProcessHost()->GetID())); | |
| 42 EXPECT_TRUE(content::WaitForLoadStop(web_contents)); | |
| 43 | |
| 44 // Scrape the set of 'origin-cell' elements, and verify that there is exactly | |
| 45 // one, and that it contains our example URL. | |
| 46 bool found_example_site = false; | |
| 47 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 48 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 49 "window.setPagePopulatedCallbackForTest(function() {" | |
| 50 " var origin_cells = " | |
| 51 "Array.from(document.getElementsByClassName('origin-cell'));" | |
| 52 " var found = origin_cells.reduce(function(found, element) {" | |
| 53 " return found || (element.innerHTML == 'http://www.example.com/');" | |
| 54 " }, false);" | |
| 55 " window.domAutomationController.send(found);" | |
| 56 "});", | |
| 57 &found_example_site)); | |
| 58 EXPECT_TRUE(found_example_site); | |
| 59 } | |
| OLD | NEW |