extension_icon_source_apitest.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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. 4 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/common/chrome_switches.h" 12#include "chrome/test/base/ui_test_utils.h" 13#include "content/public/browser/web_contents.h" 14#include "content/public/test/browser_test_utils.h" 15#include "googleurl/src/gurl.h" 16#include "net/dns/mock_host_resolver.h" 17 18class ExtensionIconSourceTest : public ExtensionApiTest { 19 protected: 20 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 21 ExtensionApiTest::SetUpCommandLine(command_line); 22 command_line->AppendSwitch(switches::kAllowLegacyExtensionManifests); 23 } 24}; 25 26IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoaded) { 27 base::FilePath basedir = test_data_dir_.AppendASCII("icons"); 28 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_with_permission"))); 29 ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_no_permission"))); 30 std::string result; 31 32 // Test that the icons are loaded and that the chrome://extension-icon 33 // parameters work correctly. 34 ui_test_utils::NavigateToURL( 35 browser(), 36 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html")); 37 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 38 browser()->tab_strip_model()->GetActiveWebContents(), 39 "window.domAutomationController.send(document.title)", 40 &result)); 41 EXPECT_EQ(result, "Loaded"); 42 43 // Verify that the an extension can't load chrome://extension-icon icons 44 // without the management permission. 45 ui_test_utils::NavigateToURL( 46 browser(), 47 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html")); 48 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 49 browser()->tab_strip_model()->GetActiveWebContents(), 50 "window.domAutomationController.send(document.title)", 51 &result)); 52 EXPECT_EQ(result, "Not Loaded"); 53} 54 55IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, InvalidURL) { 56 std::string result; 57 58 // Test that navigation to an invalid url works. 59 ui_test_utils::NavigateToURL( 60 browser(), 61 GURL("chrome://extension-icon/invalid")); 62 63 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 64 browser()->tab_strip_model()->GetActiveWebContents(), 65 "window.domAutomationController.send(document.title)", 66 &result)); 67 EXPECT_EQ(result, "invalid (96\xC3\x97""96)"); 68} 69 70IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, IconsLoadedIncognito) { 71 base::FilePath basedir = test_data_dir_.AppendASCII("icons"); 72 ASSERT_TRUE(LoadExtensionIncognito( 73 basedir.AppendASCII("extension_with_permission"))); 74 ASSERT_TRUE(LoadExtensionIncognito( 75 basedir.AppendASCII("extension_no_permission"))); 76 std::string result; 77 78 // Test that the icons are loaded and that the chrome://extension-icon 79 // parameters work correctly. 80 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( 81 browser()->profile(), 82 GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html")); 83 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 84 otr_browser->tab_strip_model()->GetActiveWebContents(), 85 "window.domAutomationController.send(document.title)", 86 &result)); 87 EXPECT_EQ(result, "Loaded"); 88 89 // Verify that the an extension can't load chrome://extension-icon icons 90 // without the management permission. 91 ui_test_utils::OpenURLOffTheRecord( 92 browser()->profile(), 93 GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html")); 94 ASSERT_TRUE(content::ExecuteScriptAndExtractString( 95 otr_browser->tab_strip_model()->GetActiveWebContents(), 96 "window.domAutomationController.send(document.title)", 97 &result)); 98 EXPECT_EQ(result, "Not Loaded"); 99} 100