1 // Copyright (c) 2012 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 "base/logging.h"
6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/test/browser_test_utils.h"
14 #include "extensions/common/switches.h"
15 #include "net/dns/mock_host_resolver.h"
18 class ExtensionIconSourceTest
: public ExtensionApiTest
{
20 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
21 ExtensionApiTest::SetUpCommandLine(command_line
);
22 command_line
->AppendSwitch(
23 extensions::switches::kAllowLegacyExtensionManifests
);
27 // Times out on Mac and Win. http://crbug.com/238705
28 #if defined(OS_WIN) || defined(OS_MACOSX)
29 #define MAYBE_IconsLoaded DISABLED_IconsLoaded
31 #define MAYBE_IconsLoaded IconsLoaded
34 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest
, MAYBE_IconsLoaded
) {
35 base::FilePath basedir
= test_data_dir_
.AppendASCII("icons");
36 ASSERT_TRUE(LoadExtension(basedir
.AppendASCII("extension_with_permission")));
37 ASSERT_TRUE(LoadExtension(basedir
.AppendASCII("extension_no_permission")));
40 // Test that the icons are loaded and that the chrome://extension-icon
41 // parameters work correctly.
42 ui_test_utils::NavigateToURL(
44 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html"));
45 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
46 browser()->tab_strip_model()->GetActiveWebContents(),
47 "window.domAutomationController.send(document.title)",
49 EXPECT_EQ(result
, "Loaded");
51 // Verify that the an extension can't load chrome://extension-icon icons
52 // without the management permission.
53 ui_test_utils::NavigateToURL(
55 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html"));
56 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
57 browser()->tab_strip_model()->GetActiveWebContents(),
58 "window.domAutomationController.send(document.title)",
60 EXPECT_EQ(result
, "Not Loaded");
63 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest
, InvalidURL
) {
66 // Test that navigation to an invalid url works.
67 ui_test_utils::NavigateToURL(
69 GURL("chrome://extension-icon/invalid"));
71 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
72 browser()->tab_strip_model()->GetActiveWebContents(),
73 "window.domAutomationController.send(document.title)",
75 EXPECT_EQ(result
, "invalid (96\xC3\x97""96)");
78 // Times out on Mac and Win. http://crbug.com/238705
79 #if defined(OS_WIN) || defined(OS_MACOSX)
80 #define MAYBE_IconsLoadedIncognito DISABLED_IconsLoadedIncognito
82 #define MAYBE_IconsLoadedIncognito IconsLoadedIncognito
85 IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest
, MAYBE_IconsLoadedIncognito
) {
86 base::FilePath basedir
= test_data_dir_
.AppendASCII("icons");
87 ASSERT_TRUE(LoadExtensionIncognito(
88 basedir
.AppendASCII("extension_with_permission")));
89 ASSERT_TRUE(LoadExtensionIncognito(
90 basedir
.AppendASCII("extension_no_permission")));
93 // Test that the icons are loaded and that the chrome://extension-icon
94 // parameters work correctly.
95 Browser
* otr_browser
= OpenURLOffTheRecord(
97 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html"));
98 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
99 otr_browser
->tab_strip_model()->GetActiveWebContents(),
100 "window.domAutomationController.send(document.title)",
102 EXPECT_EQ(result
, "Loaded");
104 // Verify that the an extension can't load chrome://extension-icon icons
105 // without the management permission.
107 browser()->profile(),
108 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html"));
109 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
110 otr_browser
->tab_strip_model()->GetActiveWebContents(),
111 "window.domAutomationController.send(document.title)",
113 EXPECT_EQ(result
, "Not Loaded");