pkasting | a71de624 | 2016-08-24 00:04:41 | [diff] [blame] | 1 | // Copyright 2016 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 "chrome/browser/extensions/extension_browsertest.h" |
| 6 | #include "chrome/browser/extensions/extension_service.h" |
| 7 | #include "extensions/test/extension_test_message_listener.h" |
| 8 | |
| 9 | namespace extensions { |
| 10 | |
| 11 | // Tests that chrome://theme/ URLs are only accessible to component extensions. |
| 12 | IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, |
| 13 | OnlyComponentExtensionsCanAccessChromeThemeUrls) { |
| 14 | const base::FilePath extension_path( |
| 15 | test_data_dir_.AppendASCII("browsertest") |
| 16 | .AppendASCII("chrome_theme_url")); |
| 17 | ExtensionTestMessageListener listener(false); |
| 18 | |
| 19 | // First try loading the extension as a non-component extension. The |
| 20 | // chrome://theme/ image referenced in the extension should fail to load. |
| 21 | const Extension* extension = LoadExtension(extension_path); |
| 22 | ASSERT_TRUE(extension); |
| 23 | EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 24 | EXPECT_EQ("not loaded", listener.message()); |
| 25 | |
| 26 | // Unload the extension so we can reload it below with no chance of side |
| 27 | // effects. |
| 28 | extension_service()->UnloadExtension(extension->id(), |
limasdf | 0deef204 | 2017-05-03 19:17:17 | [diff] [blame] | 29 | UnloadedExtensionReason::UNINSTALL); |
pkasting | a71de624 | 2016-08-24 00:04:41 | [diff] [blame] | 30 | listener.Reset(); |
| 31 | |
| 32 | // Now try loading the extension as a component extension. This time the |
| 33 | // referenced image should load successfully. |
| 34 | ASSERT_TRUE(LoadExtensionAsComponent(extension_path)); |
| 35 | EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 36 | EXPECT_EQ("loaded", listener.message()); |
| 37 | } |
| 38 | |
| 39 | } // namespace extensions |