Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / webui / uber / uber_ui_browsertest.cc
blob6ec293ccad9b8321f2127a83ca758c8f005550eb
1 // Copyright (c) 2015 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.
5 #include <string>
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/test_extension_system.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/url_constants.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "chrome/test/base/web_ui_browser_test.h"
15 #include "content/public/test/browser_test_utils.h"
16 #include "extensions/browser/extension_registry.h"
17 #include "extensions/common/extension.h"
18 #include "extensions/common/extension_builder.h"
20 class UberUIBrowserTest : public WebUIBrowserTest {};
22 IN_PROC_BROWSER_TEST_F(UberUIBrowserTest, HistoryOverride) {
23 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIUberFrameURL));
24 content::WebContents* tab =
25 browser()->tab_strip_model()->GetActiveWebContents();
27 // Inject script. This script will be called when Extension is loaded.
28 const std::string inject_script =
29 "var is_called_override = false;"
30 "var uber_frame = {};"
31 "uber_frame.setNavigationOverride = function(controls, override) { "
32 "is_called_override = true; };";
34 ASSERT_TRUE(content::ExecuteScript(tab, inject_script));
36 scoped_refptr<const extensions::Extension> extension =
37 extensions::ExtensionBuilder()
38 .SetManifest(extensions::DictionaryBuilder()
39 .Set("name", "History Override")
40 .Set("version", "1")
41 .Set("manifest_version", 2)
42 .Set("permission",
43 extensions::ListBuilder().Append("history")))
44 .Build();
46 ExtensionService* service = extensions::ExtensionSystem::Get(
47 browser()->profile())->extension_service();
48 // Load extension. UberUI overrides history navigation.
49 // In this test, injected script will be called instead.
50 service->AddExtension(extension.get());
52 bool called_override;
53 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
54 tab, "domAutomationController.send(is_called_override);",
55 &called_override));
56 EXPECT_TRUE(called_override);