Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: chrome/common/extensions/command_unittest.cc

Issue 23445013: Parse media keys for named command in the manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/extensions/command.h" 5 #include "chrome/common/extensions/command.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 25 matching lines...) Expand all
36 const ui::Accelerator ctrl_left = ui::Accelerator(ui::VKEY_LEFT, ctrl); 36 const ui::Accelerator ctrl_left = ui::Accelerator(ui::VKEY_LEFT, ctrl);
37 const ui::Accelerator ctrl_right = ui::Accelerator(ui::VKEY_RIGHT, ctrl); 37 const ui::Accelerator ctrl_right = ui::Accelerator(ui::VKEY_RIGHT, ctrl);
38 const ui::Accelerator ctrl_up = ui::Accelerator(ui::VKEY_UP, ctrl); 38 const ui::Accelerator ctrl_up = ui::Accelerator(ui::VKEY_UP, ctrl);
39 const ui::Accelerator ctrl_down = ui::Accelerator(ui::VKEY_DOWN, ctrl); 39 const ui::Accelerator ctrl_down = ui::Accelerator(ui::VKEY_DOWN, ctrl);
40 const ui::Accelerator ctrl_ins = ui::Accelerator(ui::VKEY_INSERT, ctrl); 40 const ui::Accelerator ctrl_ins = ui::Accelerator(ui::VKEY_INSERT, ctrl);
41 const ui::Accelerator ctrl_del = ui::Accelerator(ui::VKEY_DELETE, ctrl); 41 const ui::Accelerator ctrl_del = ui::Accelerator(ui::VKEY_DELETE, ctrl);
42 const ui::Accelerator ctrl_home = ui::Accelerator(ui::VKEY_HOME, ctrl); 42 const ui::Accelerator ctrl_home = ui::Accelerator(ui::VKEY_HOME, ctrl);
43 const ui::Accelerator ctrl_end = ui::Accelerator(ui::VKEY_END, ctrl); 43 const ui::Accelerator ctrl_end = ui::Accelerator(ui::VKEY_END, ctrl);
44 const ui::Accelerator ctrl_pgup = ui::Accelerator(ui::VKEY_PRIOR, ctrl); 44 const ui::Accelerator ctrl_pgup = ui::Accelerator(ui::VKEY_PRIOR, ctrl);
45 const ui::Accelerator ctrl_pgdwn = ui::Accelerator(ui::VKEY_NEXT, ctrl); 45 const ui::Accelerator ctrl_pgdwn = ui::Accelerator(ui::VKEY_NEXT, ctrl);
46 const ui::Accelerator next_track =
47 ui::Accelerator(ui::VKEY_MEDIA_NEXT_TRACK, ui::EF_NONE);
48 const ui::Accelerator prev_track =
49 ui::Accelerator(ui::VKEY_MEDIA_PREV_TRACK, ui::EF_NONE);
50 const ui::Accelerator play_pause =
51 ui::Accelerator(ui::VKEY_MEDIA_PLAY_PAUSE, ui::EF_NONE);
52 const ui::Accelerator stop =
53 ui::Accelerator(ui::VKEY_MEDIA_STOP, ui::EF_NONE);
46 54
47 const struct { 55 const struct {
48 bool expected_result; 56 bool expected_result;
49 ui::Accelerator accelerator; 57 ui::Accelerator accelerator;
50 const char* command_name; 58 const char* command_name;
51 const char* key; 59 const char* key;
52 const char* description; 60 const char* description;
53 } kTests[] = { 61 } kTests[] = {
54 // Negative test (one or more missing required fields). We don't need to 62 // Negative test (one or more missing required fields). We don't need to
55 // test |command_name| being blank as it is used as a key in the manifest, 63 // test |command_name| being blank as it is used as a key in the manifest,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 { true, ctrl_left, "_execute_browser_action", "Ctrl+Left", "" }, 101 { true, ctrl_left, "_execute_browser_action", "Ctrl+Left", "" },
94 { true, ctrl_right, "_execute_browser_action", "Ctrl+Right", "" }, 102 { true, ctrl_right, "_execute_browser_action", "Ctrl+Right", "" },
95 { true, ctrl_up, "_execute_browser_action", "Ctrl+Up", "" }, 103 { true, ctrl_up, "_execute_browser_action", "Ctrl+Up", "" },
96 { true, ctrl_down, "_execute_browser_action", "Ctrl+Down", "" }, 104 { true, ctrl_down, "_execute_browser_action", "Ctrl+Down", "" },
97 { true, ctrl_ins, "_execute_browser_action", "Ctrl+Insert", "" }, 105 { true, ctrl_ins, "_execute_browser_action", "Ctrl+Insert", "" },
98 { true, ctrl_del, "_execute_browser_action", "Ctrl+Delete", "" }, 106 { true, ctrl_del, "_execute_browser_action", "Ctrl+Delete", "" },
99 { true, ctrl_home, "_execute_browser_action", "Ctrl+Home", "" }, 107 { true, ctrl_home, "_execute_browser_action", "Ctrl+Home", "" },
100 { true, ctrl_end, "_execute_browser_action", "Ctrl+End", "" }, 108 { true, ctrl_end, "_execute_browser_action", "Ctrl+End", "" },
101 { true, ctrl_pgup, "_execute_browser_action", "Ctrl+PageUp", "" }, 109 { true, ctrl_pgup, "_execute_browser_action", "Ctrl+PageUp", "" },
102 { true, ctrl_pgdwn, "_execute_browser_action", "Ctrl+PageDown", "" }, 110 { true, ctrl_pgdwn, "_execute_browser_action", "Ctrl+PageDown", "" },
111 // Media keys.
112 { true, next_track, "command", "MediaNextTrack", "description"},
113 { true, play_pause, "command", "MediaPlayPause", "description"},
114 { true, prev_track, "command", "MediaPrevTrack", "description"},
115 { true, stop, "command", "MediaStop", "description"},
116 { false, none, "_execute_browser_action", "MediaNextTrack", ""},
117 { false, none, "_execute_page_action", "MediaPrevTrack", ""},
Finnur 2013/08/28 14:15:16 Add a failure test for Ctrl+Shift+MediaKey (one pe
zhchbin 2013/08/29 14:27:11 Done.
103 }; 118 };
104 119
105 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) { 120 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTests); ++i) {
106 // First parse the command as a simple string. 121 // First parse the command as a simple string.
107 scoped_ptr<base::DictionaryValue> input(new base::DictionaryValue); 122 scoped_ptr<base::DictionaryValue> input(new base::DictionaryValue);
108 input->SetString("suggested_key", kTests[i].key); 123 input->SetString("suggested_key", kTests[i].key);
109 input->SetString("description", kTests[i].description); 124 input->SetString("description", kTests[i].description);
110 125
111 SCOPED_TRACE(std::string("Command name: |") + kTests[i].command_name + 126 SCOPED_TRACE(std::string("Command name: |") + kTests[i].command_name +
112 "| key: |" + kTests[i].key + 127 "| key: |" + kTests[i].key +
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 key_dict->SetString("windows", "Ctrl+Shift+W"); 240 key_dict->SetString("windows", "Ctrl+Shift+W");
226 #endif 241 #endif
227 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); 242 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error));
228 243
229 // Make sure Mac specific keys are not processed on other platforms. 244 // Make sure Mac specific keys are not processed on other platforms.
230 #if !defined(OS_MACOSX) 245 #if !defined(OS_MACOSX)
231 key_dict->SetString("windows", "Command+Shift+M"); 246 key_dict->SetString("windows", "Command+Shift+M");
232 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error)); 247 EXPECT_FALSE(command.Parse(input.get(), command_name, 0, &error));
233 #endif 248 #endif
234 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698