| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/scoped_vector.h" | 10 #include "base/scoped_vector.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // Base class for tests. | 30 // Base class for tests. |
| 31 class ExtensionMenuManagerTest : public testing::Test { | 31 class ExtensionMenuManagerTest : public testing::Test { |
| 32 public: | 32 public: |
| 33 ExtensionMenuManagerTest() : next_id_(1) {} | 33 ExtensionMenuManagerTest() : next_id_(1) {} |
| 34 ~ExtensionMenuManagerTest() {} | 34 ~ExtensionMenuManagerTest() {} |
| 35 | 35 |
| 36 // Returns a test item. | 36 // Returns a test item. |
| 37 ExtensionMenuItem* CreateTestItem(Extension* extension) { | 37 ExtensionMenuItem* CreateTestItem(Extension* extension) { |
| 38 ExtensionMenuItem::Type type = ExtensionMenuItem::NORMAL; | 38 ExtensionMenuItem::Type type = ExtensionMenuItem::NORMAL; |
| 39 ExtensionMenuItem::ContextList contexts(ExtensionMenuItem::ALL); | 39 ExtensionMenuItem::ContextList contexts(ExtensionMenuItem::ALL); |
| 40 ExtensionMenuItem::Id id(extension->id(), next_id_++); | 40 ExtensionMenuItem::Id id(NULL, extension->id(), next_id_++); |
| 41 return new ExtensionMenuItem(id, "test", false, type, contexts); | 41 return new ExtensionMenuItem(id, "test", false, type, contexts); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Creates and returns a test Extension. The caller does *not* own the return | 44 // Creates and returns a test Extension. The caller does *not* own the return |
| 45 // value. | 45 // value. |
| 46 Extension* AddExtension(std::string name) { | 46 Extension* AddExtension(std::string name) { |
| 47 scoped_refptr<Extension> extension = prefs_.AddExtension(name); | 47 scoped_refptr<Extension> extension = prefs_.AddExtension(name); |
| 48 extensions_.push_back(extension); | 48 extensions_.push_back(extension); |
| 49 return extension; | 49 return extension; |
| 50 } | 50 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 ExtensionMenuItem::Id id3 = item3->id(); | 87 ExtensionMenuItem::Id id3 = item3->id(); |
| 88 std::string extension_id = item3->extension_id(); | 88 std::string extension_id = item3->extension_id(); |
| 89 ASSERT_TRUE(manager_.AddContextItem(extension, item3)); | 89 ASSERT_TRUE(manager_.AddContextItem(extension, item3)); |
| 90 ASSERT_EQ(item3, manager_.GetItemById(id3)); | 90 ASSERT_EQ(item3, manager_.GetItemById(id3)); |
| 91 ASSERT_EQ(3u, manager_.MenuItems(extension_id)->size()); | 91 ASSERT_EQ(3u, manager_.MenuItems(extension_id)->size()); |
| 92 ASSERT_TRUE(manager_.RemoveContextMenuItem(id3)); | 92 ASSERT_TRUE(manager_.RemoveContextMenuItem(id3)); |
| 93 ASSERT_EQ(NULL, manager_.GetItemById(id3)); | 93 ASSERT_EQ(NULL, manager_.GetItemById(id3)); |
| 94 ASSERT_EQ(2u, manager_.MenuItems(extension_id)->size()); | 94 ASSERT_EQ(2u, manager_.MenuItems(extension_id)->size()); |
| 95 | 95 |
| 96 // Make sure removing a non-existent item returns false. | 96 // Make sure removing a non-existent item returns false. |
| 97 ExtensionMenuItem::Id id(extension->id(), id3.second + 50); | 97 ExtensionMenuItem::Id id(NULL, extension->id(), id3.uid + 50); |
| 98 ASSERT_FALSE(manager_.RemoveContextMenuItem(id)); | 98 ASSERT_FALSE(manager_.RemoveContextMenuItem(id)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Test adding/removing child items. | 101 // Test adding/removing child items. |
| 102 TEST_F(ExtensionMenuManagerTest, ChildFunctions) { | 102 TEST_F(ExtensionMenuManagerTest, ChildFunctions) { |
| 103 Extension* extension1 = AddExtension("1111"); | 103 Extension* extension1 = AddExtension("1111"); |
| 104 Extension* extension2 = AddExtension("2222"); | 104 Extension* extension2 = AddExtension("2222"); |
| 105 Extension* extension3 = AddExtension("3333"); | 105 Extension* extension3 = AddExtension("3333"); |
| 106 | 106 |
| 107 ExtensionMenuItem* item1 = CreateTestItem(extension1); | 107 ExtensionMenuItem* item1 = CreateTestItem(extension1); |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 ASSERT_TRUE(result.get() != NULL); | 454 ASSERT_TRUE(result.get() != NULL); |
| 455 ASSERT_EQ(Value::TYPE_LIST, value->GetType()); | 455 ASSERT_EQ(Value::TYPE_LIST, value->GetType()); |
| 456 ListValue* list = static_cast<ListValue*>(value); | 456 ListValue* list = static_cast<ListValue*>(value); |
| 457 ASSERT_EQ(2u, list->GetSize()); | 457 ASSERT_EQ(2u, list->GetSize()); |
| 458 | 458 |
| 459 DictionaryValue* info; | 459 DictionaryValue* info; |
| 460 ASSERT_TRUE(list->GetDictionary(0, &info)); | 460 ASSERT_TRUE(list->GetDictionary(0, &info)); |
| 461 | 461 |
| 462 int tmp_id = 0; | 462 int tmp_id = 0; |
| 463 ASSERT_TRUE(info->GetInteger("menuItemId", &tmp_id)); | 463 ASSERT_TRUE(info->GetInteger("menuItemId", &tmp_id)); |
| 464 ASSERT_EQ(id.second, tmp_id); | 464 ASSERT_EQ(id.uid, tmp_id); |
| 465 | 465 |
| 466 std::string tmp; | 466 std::string tmp; |
| 467 ASSERT_TRUE(info->GetString("mediaType", &tmp)); | 467 ASSERT_TRUE(info->GetString("mediaType", &tmp)); |
| 468 ASSERT_EQ("image", tmp); | 468 ASSERT_EQ("image", tmp); |
| 469 ASSERT_TRUE(info->GetString("srcUrl", &tmp)); | 469 ASSERT_TRUE(info->GetString("srcUrl", &tmp)); |
| 470 ASSERT_EQ(params.src_url.spec(), tmp); | 470 ASSERT_EQ(params.src_url.spec(), tmp); |
| 471 ASSERT_TRUE(info->GetString("pageUrl", &tmp)); | 471 ASSERT_TRUE(info->GetString("pageUrl", &tmp)); |
| 472 ASSERT_EQ(params.page_url.spec(), tmp); | 472 ASSERT_EQ(params.page_url.spec(), tmp); |
| 473 | 473 |
| 474 ASSERT_TRUE(info->GetString("selectionText", &tmp)); | 474 ASSERT_TRUE(info->GetString("selectionText", &tmp)); |
| 475 ASSERT_EQ(WideToUTF8(params.selection_text), tmp); | 475 ASSERT_EQ(WideToUTF8(params.selection_text), tmp); |
| 476 | 476 |
| 477 bool bool_tmp = true; | 477 bool bool_tmp = true; |
| 478 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp)); | 478 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp)); |
| 479 ASSERT_EQ(params.is_editable, bool_tmp); | 479 ASSERT_EQ(params.is_editable, bool_tmp); |
| 480 } | 480 } |
| OLD | NEW |