Chromium Code Reviews| Index: chrome/browser/ui/webui/engagement/site_engagement_ui_browsertest.cc |
| diff --git a/chrome/browser/ui/webui/engagement/site_engagement_ui_browsertest.cc b/chrome/browser/ui/webui/engagement/site_engagement_ui_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c9090e1701b5510ba65b6f1216bef5f90071846e |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/engagement/site_engagement_ui_browsertest.cc |
| @@ -0,0 +1,59 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
dominickn
2017/03/29 07:46:33
2017 for a new file? :)
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/command_line.h" |
| +#include "chrome/browser/engagement/site_engagement_service.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_commands.h" |
| +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| +#include "chrome/common/url_constants.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/ui_test_utils.h" |
| +#include "content/public/browser/child_process_security_policy.h" |
| +#include "content/public/browser/render_process_host.h" |
| +#include "content/public/common/content_switches.h" |
| +#include "content/public/test/browser_test_utils.h" |
| +#include "content/public/test/test_utils.h" |
| + |
| +using SiteEngagementUiBrowserTest = InProcessBrowserTest; |
| + |
| +IN_PROC_BROWSER_TEST_F(SiteEngagementUiBrowserTest, Basic) { |
| + // Fake some activity to populate site engagement scores. |
| + SiteEngagementService* service = |
| + SiteEngagementService::Get(browser()->profile()); |
| + |
| + const GURL kExampleUrl = GURL("http://www.example.com/"); |
| + service->ResetBaseScoreForURL(kExampleUrl, service->GetMaxPoints()); |
| + |
| + // Navigate a tab to the site engagement WebUI. |
| + content::WebContents* web_contents = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + |
| + const GURL web_ui_url(std::string(content::kChromeUIScheme) + "://" + |
| + std::string(chrome::kChromeUISiteEngagementHost)); |
| + EXPECT_TRUE(ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| + web_contents->GetBrowserContext(), web_ui_url)); |
| + ui_test_utils::NavigateToURL(browser(), web_ui_url); |
| + EXPECT_TRUE( |
| + content::ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( |
| + web_contents->GetRenderProcessHost()->GetID())); |
| + EXPECT_TRUE(content::WaitForLoadStop(web_contents)); |
| + |
| + // Scrape the set of 'origin-cell' elements, and verify that there is exactly |
| + // one, and that it contains our example URL. |
| + bool found_example_site = false; |
| + ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| + browser()->tab_strip_model()->GetActiveWebContents(), |
| + "window.setPagePopulatedCallbackForTest(function() {" |
| + " var origin_cells = " |
| + "Array.from(document.getElementsByClassName('origin-cell'));" |
| + " var found = origin_cells.reduce(function(found, element) {" |
| + " return found || (element.innerHTML == 'http://www.example.com/');" |
| + " }, false);" |
| + " window.domAutomationController.send(found);" |
| + "});", |
| + &found_example_site)); |
| + EXPECT_TRUE(found_example_site); |
| +} |