blob: 68ac94ec417f90f56f6d2b907a2bfe21d3b7d3ed [file] [log] [blame]
[email protected]d8748142012-05-16 21:13:431// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]f83773f2011-03-02 19:15:212// 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/logging.h"
avia2f4804a2015-12-24 23:11:136#include "build/build_config.h"
[email protected]f83773f2011-03-02 19:15:217#include "chrome/browser/extensions/extension_apitest.h"
[email protected]ff8efd312011-03-21 17:33:598#include "chrome/browser/extensions/extension_service.h"
9#include "chrome/browser/profiles/profile.h"
[email protected]f83773f2011-03-02 19:15:2110#include "chrome/browser/ui/browser.h"
[email protected]47ae23372013-01-29 01:50:4811#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]af44e7fb2011-07-29 18:32:3212#include "chrome/test/base/ui_test_utils.h"
[email protected]4ca15302012-01-03 05:53:2013#include "content/public/browser/web_contents.h"
[email protected]7d478cb2012-07-24 17:19:4214#include "content/public/test/browser_test_utils.h"
[email protected]49d9b142013-07-19 08:50:2715#include "extensions/common/switches.h"
[email protected]f2cb3cf2013-03-21 01:40:5316#include "net/dns/mock_host_resolver.h"
[email protected]a6483d22013-07-03 22:11:0017#include "url/gurl.h"
[email protected]f83773f2011-03-02 19:15:2118
Devlin Croninef3e37e2018-05-14 23:47:2419using ExtensionIconSourceTest = extensions::ExtensionApiTest;
[email protected]f83773f2011-03-02 19:15:2120
[email protected]04e51aa2013-05-07 17:46:3721// Times out on Mac and Win. http://crbug.com/238705
22#if defined(OS_WIN) || defined(OS_MACOSX)
23#define MAYBE_IconsLoaded DISABLED_IconsLoaded
24#else
25#define MAYBE_IconsLoaded IconsLoaded
26#endif
27
28IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, MAYBE_IconsLoaded) {
[email protected]650b2d52013-02-10 03:41:4529 base::FilePath basedir = test_data_dir_.AppendASCII("icons");
[email protected]f83773f2011-03-02 19:15:2130 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_with_permission")));
31 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_no_permission")));
32 std::string result;
33
34 // Test that the icons are loaded and that the chrome://extension-icon
35 // parameters work correctly.
36 ui_test_utils::NavigateToURL(
37 browser(),
38 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html"));
[email protected]b6987e02013-01-04 18:30:4339 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]47ae23372013-01-29 01:50:4840 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:1341 "window.domAutomationController.send(document.title)",
[email protected]f83773f2011-03-02 19:15:2142 &result));
43 EXPECT_EQ(result, "Loaded");
44
45 // Verify that the an extension can't load chrome://extension-icon icons
46 // without the management permission.
47 ui_test_utils::NavigateToURL(
48 browser(),
49 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html"));
[email protected]b6987e02013-01-04 18:30:4350 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]47ae23372013-01-29 01:50:4851 browser()->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:1352 "window.domAutomationController.send(document.title)",
[email protected]f83773f2011-03-02 19:15:2153 &result));
54 EXPECT_EQ(result, "Not Loaded");
55}
[email protected]ff8efd312011-03-21 17:33:5956
[email protected]7029cb742013-01-30 02:06:5557IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, InvalidURL) {
58 std::string result;
59
60 // Test that navigation to an invalid url works.
61 ui_test_utils::NavigateToURL(
62 browser(),
63 GURL("chrome://extension-icon/invalid"));
64
65 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
66 browser()->tab_strip_model()->GetActiveWebContents(),
67 "window.domAutomationController.send(document.title)",
68 &result));
69 EXPECT_EQ(result, "invalid (96\xC3\x97""96)");
70}
71
[email protected]04e51aa2013-05-07 17:46:3772// Times out on Mac and Win. http://crbug.com/238705
73#if defined(OS_WIN) || defined(OS_MACOSX)
74#define MAYBE_IconsLoadedIncognito DISABLED_IconsLoadedIncognito
75#else
76#define MAYBE_IconsLoadedIncognito IconsLoadedIncognito
77#endif
78
79IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, MAYBE_IconsLoadedIncognito) {
[email protected]650b2d52013-02-10 03:41:4580 base::FilePath basedir = test_data_dir_.AppendASCII("icons");
[email protected]ff8efd312011-03-21 17:33:5981 ASSERT_TRUE(LoadExtensionIncognito(
82 basedir.AppendASCII("extension_with_permission")));
83 ASSERT_TRUE(LoadExtensionIncognito(
84 basedir.AppendASCII("extension_no_permission")));
85 std::string result;
86
87 // Test that the icons are loaded and that the chrome://extension-icon
88 // parameters work correctly.
erikchenff8b5c7a2015-07-13 23:41:2089 Browser* otr_browser = OpenURLOffTheRecord(
[email protected]ff8efd312011-03-21 17:33:5990 browser()->profile(),
91 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html"));
[email protected]b6987e02013-01-04 18:30:4392 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]47ae23372013-01-29 01:50:4893 otr_browser->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:1394 "window.domAutomationController.send(document.title)",
[email protected]ff8efd312011-03-21 17:33:5995 &result));
96 EXPECT_EQ(result, "Loaded");
97
98 // Verify that the an extension can't load chrome://extension-icon icons
99 // without the management permission.
erikchenff8b5c7a2015-07-13 23:41:20100 OpenURLOffTheRecord(
[email protected]ff8efd312011-03-21 17:33:59101 browser()->profile(),
102 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html"));
[email protected]b6987e02013-01-04 18:30:43103 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
[email protected]47ae23372013-01-29 01:50:48104 otr_browser->tab_strip_model()->GetActiveWebContents(),
[email protected]06bc5d92013-01-02 22:44:13105 "window.domAutomationController.send(document.title)",
[email protected]ff8efd312011-03-21 17:33:59106 &result));
107 EXPECT_EQ(result, "Not Loaded");
108}