OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 13 matching lines...) Expand all Loading... |
24 #include "webkit/glue/context_menu.h" | 24 #include "webkit/glue/context_menu.h" |
25 | 25 |
26 using testing::_; | 26 using testing::_; |
27 using testing::AtLeast; | 27 using testing::AtLeast; |
28 using testing::Return; | 28 using testing::Return; |
29 using testing::SaveArg; | 29 using testing::SaveArg; |
30 | 30 |
31 // Base class for tests. | 31 // Base class for tests. |
32 class ExtensionMenuManagerTest : public testing::Test { | 32 class ExtensionMenuManagerTest : public testing::Test { |
33 public: | 33 public: |
34 ExtensionMenuManagerTest() : next_id_(1) {} | 34 ExtensionMenuManagerTest() |
35 ~ExtensionMenuManagerTest() {} | 35 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 36 file_thread_(BrowserThread::FILE, &message_loop_), |
| 37 next_id_(1) { |
| 38 } |
36 | 39 |
37 // Returns a test item. | 40 // Returns a test item. |
38 ExtensionMenuItem* CreateTestItem(Extension* extension) { | 41 ExtensionMenuItem* CreateTestItem(Extension* extension) { |
39 ExtensionMenuItem::Type type = ExtensionMenuItem::NORMAL; | 42 ExtensionMenuItem::Type type = ExtensionMenuItem::NORMAL; |
40 ExtensionMenuItem::ContextList contexts(ExtensionMenuItem::ALL); | 43 ExtensionMenuItem::ContextList contexts(ExtensionMenuItem::ALL); |
41 ExtensionMenuItem::Id id(NULL, extension->id(), next_id_++); | 44 ExtensionMenuItem::Id id(NULL, extension->id(), next_id_++); |
42 return new ExtensionMenuItem(id, "test", false, type, contexts); | 45 return new ExtensionMenuItem(id, "test", false, type, contexts); |
43 } | 46 } |
44 | 47 |
45 // Creates and returns a test Extension. The caller does *not* own the return | 48 // Creates and returns a test Extension. The caller does *not* own the return |
46 // value. | 49 // value. |
47 Extension* AddExtension(std::string name) { | 50 Extension* AddExtension(std::string name) { |
48 scoped_refptr<Extension> extension = prefs_.AddExtension(name); | 51 scoped_refptr<Extension> extension = prefs_.AddExtension(name); |
49 extensions_.push_back(extension); | 52 extensions_.push_back(extension); |
50 return extension; | 53 return extension; |
51 } | 54 } |
52 | 55 |
53 protected: | 56 protected: |
| 57 MessageLoopForUI message_loop_; |
| 58 BrowserThread ui_thread_; |
| 59 BrowserThread file_thread_; |
| 60 |
54 ExtensionMenuManager manager_; | 61 ExtensionMenuManager manager_; |
55 ExtensionList extensions_; | 62 ExtensionList extensions_; |
56 TestExtensionPrefs prefs_; | 63 TestExtensionPrefs prefs_; |
57 int next_id_; | 64 int next_id_; |
58 | 65 |
59 private: | 66 private: |
60 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManagerTest); | 67 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManagerTest); |
61 }; | 68 }; |
62 | 69 |
63 // Tests adding, getting, and removing items. | 70 // Tests adding, getting, and removing items. |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 409 |
403 ASSERT_FALSE(manager_.context_items_.empty()); | 410 ASSERT_FALSE(manager_.context_items_.empty()); |
404 | 411 |
405 manager_.RemoveContextMenuItem(item1->id()); | 412 manager_.RemoveContextMenuItem(item1->id()); |
406 manager_.RemoveContextMenuItem(item2->id()); | 413 manager_.RemoveContextMenuItem(item2->id()); |
407 | 414 |
408 ASSERT_TRUE(manager_.context_items_.empty()); | 415 ASSERT_TRUE(manager_.context_items_.empty()); |
409 } | 416 } |
410 | 417 |
411 TEST_F(ExtensionMenuManagerTest, ExecuteCommand) { | 418 TEST_F(ExtensionMenuManagerTest, ExecuteCommand) { |
412 MessageLoopForUI message_loop; | |
413 BrowserThread ui_thread(BrowserThread::UI, &message_loop); | |
414 | |
415 MockTestingProfile profile; | 419 MockTestingProfile profile; |
416 | 420 |
417 scoped_ptr<MockExtensionEventRouter> mock_event_router( | 421 scoped_ptr<MockExtensionEventRouter> mock_event_router( |
418 new MockExtensionEventRouter(&profile)); | 422 new MockExtensionEventRouter(&profile)); |
419 | 423 |
420 ContextMenuParams params; | 424 ContextMenuParams params; |
421 params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 425 params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
422 params.src_url = GURL("http://foo.bar/image.png"); | 426 params.src_url = GURL("http://foo.bar/image.png"); |
423 params.page_url = GURL("http://foo.bar"); | 427 params.page_url = GURL("http://foo.bar"); |
424 params.selection_text = ASCIIToUTF16("Hello World"); | 428 params.selection_text = ASCIIToUTF16("Hello World"); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 ASSERT_EQ(params.page_url.spec(), tmp); | 478 ASSERT_EQ(params.page_url.spec(), tmp); |
475 | 479 |
476 string16 tmp16; | 480 string16 tmp16; |
477 ASSERT_TRUE(info->GetString("selectionText", &tmp16)); | 481 ASSERT_TRUE(info->GetString("selectionText", &tmp16)); |
478 ASSERT_EQ(params.selection_text, tmp16); | 482 ASSERT_EQ(params.selection_text, tmp16); |
479 | 483 |
480 bool bool_tmp = true; | 484 bool bool_tmp = true; |
481 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp)); | 485 ASSERT_TRUE(info->GetBoolean("editable", &bool_tmp)); |
482 ASSERT_EQ(params.is_editable, bool_tmp); | 486 ASSERT_EQ(params.is_editable, bool_tmp); |
483 } | 487 } |
OLD | NEW |