1 // Copyright (c) 2013 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 "chrome/browser/extensions/api/commands/command_service.h"
6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "content/public/test/browser_test.h"
9 #include "content/public/test/test_utils.h"
10 #include "extensions/common/manifest_constants.h"
12 namespace extensions {
14 typedef ExtensionApiTest CommandServiceTest;
16 IN_PROC_BROWSER_TEST_F(CommandServiceTest, RemoveShortcutSurvivesUpdate) {
17 base::ScopedTempDir scoped_temp_dir;
18 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
19 base::FilePath pem_path = test_data_dir_.
20 AppendASCII("keybinding").AppendASCII("keybinding.pem");
21 base::FilePath path_v1 = PackExtensionWithOptions(
22 test_data_dir_.AppendASCII("keybinding").AppendASCII("update")
24 scoped_temp_dir.path().AppendASCII("v1.crx"),
27 base::FilePath path_v2 = PackExtensionWithOptions(
28 test_data_dir_.AppendASCII("keybinding").AppendASCII("update")
30 scoped_temp_dir.path().AppendASCII("v2.crx"),
34 ExtensionService* service = ExtensionSystem::Get(browser()->profile())->
36 CommandService* command_service = CommandService::Get(browser()->profile());
38 const char kId[] = "pgoakhfeplldmjheffidklpoklkppipp";
40 // Install v1 of the extension.
41 ASSERT_TRUE(InstallExtension(path_v1, 1));
42 EXPECT_TRUE(service->GetExtensionById(kId, false) != NULL);
44 // Verify it has a command of Alt+Shift+F.
45 ui::Accelerator accelerator = command_service->FindCommandByName(
46 kId, manifest_values::kBrowserActionCommandEvent).accelerator();
47 EXPECT_EQ(ui::VKEY_F, accelerator.key_code());
48 EXPECT_FALSE(accelerator.IsCtrlDown());
49 EXPECT_TRUE(accelerator.IsShiftDown());
50 EXPECT_TRUE(accelerator.IsAltDown());
52 // Remove the keybinding.
53 command_service->RemoveKeybindingPrefs(
54 kId, manifest_values::kBrowserActionCommandEvent);
56 // Verify it got removed.
57 accelerator = command_service->FindCommandByName(
58 kId, manifest_values::kBrowserActionCommandEvent).accelerator();
59 EXPECT_EQ(ui::VKEY_UNKNOWN, accelerator.key_code());
61 // Update to version 2.
62 EXPECT_TRUE(UpdateExtension(kId, path_v2, 0));
63 EXPECT_TRUE(service->GetExtensionById(kId, false) != NULL);
65 // Verify it is still set to nothing.
66 accelerator = command_service->FindCommandByName(
67 kId, manifest_values::kBrowserActionCommandEvent).accelerator();
68 EXPECT_EQ(ui::VKEY_UNKNOWN, accelerator.key_code());
71 } // namespace extensions