Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / extensions / extension_web_ui_unittest.cc
blobf912016d583c91ead574bc784ac559780c4ec413
1 // Copyright 2014 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/command_line.h"
6 #include "base/message_loop/message_loop.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_web_ui.h"
9 #include "chrome/browser/extensions/test_extension_system.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "content/public/test/test_browser_thread.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/extension_builder.h"
14 #include "extensions/common/manifest_constants.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 #if defined(OS_CHROMEOS)
18 #include "chrome/browser/chromeos/login/user_manager.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "chrome/browser/chromeos/settings/device_settings_service.h"
21 #endif
23 namespace extensions {
25 class ExtensionWebUITest : public testing::Test {
26 public:
27 ExtensionWebUITest()
28 : ui_thread_(content::BrowserThread::UI, &message_loop_) {}
30 protected:
31 virtual void SetUp() OVERRIDE {
32 profile_.reset(new TestingProfile());
33 TestExtensionSystem* system =
34 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile_.get()));
35 extension_service_ = system->CreateExtensionService(
36 CommandLine::ForCurrentProcess(), base::FilePath(), false);
39 virtual void TearDown() OVERRIDE {
40 profile_.reset();
41 message_loop_.RunUntilIdle();
44 scoped_ptr<TestingProfile> profile_;
45 ExtensionService* extension_service_;
46 base::MessageLoop message_loop_;
47 content::TestBrowserThread ui_thread_;
49 #if defined OS_CHROMEOS
50 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
51 chromeos::ScopedTestCrosSettings test_cros_settings_;
52 chromeos::ScopedTestUserManager test_user_manager_;
53 #endif
56 // Test that component extension url overrides have lower priority than
57 // non-component extension url overrides.
58 TEST_F(ExtensionWebUITest, ExtensionURLOverride) {
59 // Register a non-component extension.
60 extensions::DictionaryBuilder manifest;
61 manifest.Set(manifest_keys::kName, "ext1")
62 .Set(manifest_keys::kVersion, "0.1")
63 .Set(std::string(manifest_keys::kChromeURLOverrides),
64 extensions::DictionaryBuilder().Set("bookmarks", "1.html"));
65 scoped_refptr<Extension> ext_unpacked(
66 extensions::ExtensionBuilder()
67 .SetManifest(manifest)
68 .SetLocation(Manifest::UNPACKED)
69 .SetID("abcdefghijabcdefghijabcdefghijaa")
70 .Build());
71 profile_->GetExtensionService()->AddExtension(ext_unpacked.get());
73 GURL expected_unpacked_override_url(std::string(ext_unpacked->url().spec()) +
74 "1.html");
75 GURL url("chrome://bookmarks");
76 EXPECT_TRUE(ExtensionWebUI::HandleChromeURLOverride(&url, profile_.get()));
77 EXPECT_EQ(url, expected_unpacked_override_url);
79 // Register a component extension
80 extensions::DictionaryBuilder manifest2;
81 manifest2.Set(manifest_keys::kName, "ext2")
82 .Set(manifest_keys::kVersion, "0.1")
83 .Set(std::string(manifest_keys::kChromeURLOverrides),
84 extensions::DictionaryBuilder().Set("bookmarks", "2.html"));
85 scoped_refptr<Extension> ext_component(
86 extensions::ExtensionBuilder()
87 .SetManifest(manifest2)
88 .SetLocation(Manifest::COMPONENT)
89 .SetID("bbabcdefghijabcdefghijabcdefghij")
90 .Build());
91 profile_->GetExtensionService()->AddComponentExtension(ext_component.get());
93 // Despite being registered more recently, the component extension should
94 // not take precendence over the non-component extension.
95 url = GURL("chrome://bookmarks");
96 EXPECT_TRUE(ExtensionWebUI::HandleChromeURLOverride(&url, profile_.get()));
97 EXPECT_EQ(url, expected_unpacked_override_url);
99 GURL expected_component_override_url(
100 std::string(ext_component->url().spec()) + "2.html");
102 // Unregister non-component extension. Only component extension remaining.
103 ExtensionWebUI::UnregisterChromeURLOverrides(
104 profile_.get(), URLOverrides::GetChromeURLOverrides(ext_unpacked.get()));
105 url = GURL("chrome://bookmarks");
106 EXPECT_TRUE(ExtensionWebUI::HandleChromeURLOverride(&url, profile_.get()));
107 EXPECT_EQ(url, expected_component_override_url);
109 // This time the non-component extension was registered more recently and
110 // should still take precedence.
111 ExtensionWebUI::RegisterChromeURLOverrides(
112 profile_.get(), URLOverrides::GetChromeURLOverrides(ext_unpacked.get()));
113 url = GURL("chrome://bookmarks");
114 EXPECT_TRUE(ExtensionWebUI::HandleChromeURLOverride(&url, profile_.get()));
115 EXPECT_EQ(url, expected_unpacked_override_url);
118 } // namespace extensions