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

Side by Side Diff: chrome/browser/extensions/menu_manager_unittest.cc

Issue 10809094: Context Menus now uses the JSON Schema Compiler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@json_functions_as_properties
Patch Set: GetParentId returns a scoped_ptr instead of a bool Created 8 years, 4 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
« no previous file with comments | « chrome/browser/extensions/menu_manager.cc ('k') | chrome/common/extensions/api/api.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector> 5 #include <vector>
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 ASSERT_EQ(1u, manager_.MenuItems(item2->extension_id())->size()); 183 ASSERT_EQ(1u, manager_.MenuItems(item2->extension_id())->size());
184 ASSERT_EQ(item2, manager_.MenuItems(item2->extension_id())->at(0)); 184 ASSERT_EQ(item2, manager_.MenuItems(item2->extension_id())->at(0));
185 185
186 // Remove child2_item. 186 // Remove child2_item.
187 ASSERT_TRUE(manager_.RemoveContextMenuItem(id2_child)); 187 ASSERT_TRUE(manager_.RemoveContextMenuItem(id2_child));
188 ASSERT_EQ(1u, manager_.MenuItems(item2->extension_id())->size()); 188 ASSERT_EQ(1u, manager_.MenuItems(item2->extension_id())->size());
189 ASSERT_EQ(item2, manager_.MenuItems(item2->extension_id())->at(0)); 189 ASSERT_EQ(item2, manager_.MenuItems(item2->extension_id())->at(0));
190 ASSERT_EQ(0, item2->child_count()); 190 ASSERT_EQ(0, item2->child_count());
191 } 191 }
192 192
193 TEST_F(MenuManagerTest, PopulateFromValue) {
194 Extension* extension = AddExtension("test");
195
196 bool incognito = true;
197 int type = MenuItem::CHECKBOX;
198 std::string title("TITLE");
199 bool checked = true;
200 bool enabled = true;
201 MenuItem::ContextList contexts;
202 contexts.Add(MenuItem::PAGE);
203 contexts.Add(MenuItem::SELECTION);
204 int contexts_value = 0;
205 ASSERT_TRUE(contexts.ToValue()->GetAsInteger(&contexts_value));
206
207 ListValue* document_url_patterns(new ListValue());
208 document_url_patterns->Append(
209 Value::CreateStringValue("http://www.google.com/*"));
210 document_url_patterns->Append(
211 Value::CreateStringValue("http://www.reddit.com/*"));
212
213 ListValue* target_url_patterns(new ListValue());
214 target_url_patterns->Append(
215 Value::CreateStringValue("http://www.yahoo.com/*"));
216 target_url_patterns->Append(
217 Value::CreateStringValue("http://www.facebook.com/*"));
218
219 base::DictionaryValue value;
220 value.SetBoolean("incognito", incognito);
221 value.SetString("string_uid", std::string());
222 value.SetInteger("type", type);
223 value.SetString("title", title);
224 value.SetBoolean("checked", checked);
225 value.SetBoolean("enabled", enabled);
226 value.SetInteger("contexts", contexts_value);
227 value.Set("document_url_patterns", document_url_patterns);
228 value.Set("target_url_patterns", target_url_patterns);
229
230 std::string error;
231 scoped_ptr<MenuItem> item(MenuItem::Populate(extension->id(), value, &error));
232 ASSERT_TRUE(item.get());
233
234 EXPECT_EQ(extension->id(), item->extension_id());
235 EXPECT_EQ(incognito, item->incognito());
236 EXPECT_EQ(title, item->title());
237 EXPECT_EQ(checked, item->checked());
238 EXPECT_EQ(item->checked(), item->checked());
239 EXPECT_EQ(enabled, item->enabled());
240 EXPECT_EQ(contexts, item->contexts());
241
242 URLPatternSet document_url_pattern_set;
243 document_url_pattern_set.Populate(*document_url_patterns,
244 URLPattern::SCHEME_ALL,
245 true,
246 &error);
247 EXPECT_EQ(document_url_pattern_set, item->document_url_patterns());
248
249 URLPatternSet target_url_pattern_set;
250 target_url_pattern_set.Populate(*target_url_patterns,
251 URLPattern::SCHEME_ALL,
252 true,
253 &error);
254 EXPECT_EQ(target_url_pattern_set, item->target_url_patterns());
255 }
256
193 // Tests that deleting a parent properly removes descendants. 257 // Tests that deleting a parent properly removes descendants.
194 TEST_F(MenuManagerTest, DeleteParent) { 258 TEST_F(MenuManagerTest, DeleteParent) {
195 Extension* extension = AddExtension("1111"); 259 Extension* extension = AddExtension("1111");
196 260
197 // Set up 5 items to add. 261 // Set up 5 items to add.
198 MenuItem* item1 = CreateTestItem(extension); 262 MenuItem* item1 = CreateTestItem(extension);
199 MenuItem* item2 = CreateTestItem(extension); 263 MenuItem* item2 = CreateTestItem(extension);
200 MenuItem* item3 = CreateTestItemWithID(extension, "id3"); 264 MenuItem* item3 = CreateTestItemWithID(extension, "id3");
201 MenuItem* item4 = CreateTestItemWithID(extension, "id4"); 265 MenuItem* item4 = CreateTestItemWithID(extension, "id4");
202 MenuItem* item5 = CreateTestItem(extension); 266 MenuItem* item5 = CreateTestItem(extension);
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 ASSERT_TRUE(child1->checked()); 687 ASSERT_TRUE(child1->checked());
624 688
625 // Removing |parent| should cause only |child1| to be selected. 689 // Removing |parent| should cause only |child1| to be selected.
626 manager_.RemoveContextMenuItem(parent->id()); 690 manager_.RemoveContextMenuItem(parent->id());
627 parent = NULL; 691 parent = NULL;
628 ASSERT_FALSE(new_item->checked()); 692 ASSERT_FALSE(new_item->checked());
629 ASSERT_TRUE(child1->checked()); 693 ASSERT_TRUE(child1->checked());
630 } 694 }
631 695
632 } // namespace extensions 696 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/menu_manager.cc ('k') | chrome/common/extensions/api/api.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698