OLD | NEW |
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/browser/extensions/api/declarative_content/content_action.h" | 5 #include "chrome/browser/extensions/api/declarative_content/content_action.h" |
6 | 6 |
7 #include "base/test/values_test_util.h" | 7 #include "base/test/values_test_util.h" |
8 #include "chrome/browser/extensions/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
9 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
10 #include "chrome/browser/extensions/extension_tab_util.h" | 10 #include "chrome/browser/extensions/extension_tab_util.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 TestExtensionEnvironment env; | 24 TestExtensionEnvironment env; |
25 std::string error; | 25 std::string error; |
26 bool bad_message = false; | 26 bool bad_message = false; |
27 scoped_refptr<const ContentAction> result; | 27 scoped_refptr<const ContentAction> result; |
28 | 28 |
29 // Test wrong data type passed. | 29 // Test wrong data type passed. |
30 error.clear(); | 30 error.clear(); |
31 result = ContentAction::Create(*ParseJson("[]"), &error, &bad_message); | 31 result = ContentAction::Create(*ParseJson("[]"), &error, &bad_message); |
32 EXPECT_TRUE(bad_message); | 32 EXPECT_TRUE(bad_message); |
33 EXPECT_EQ("", error); | 33 EXPECT_EQ("", error); |
34 EXPECT_FALSE(result); | 34 EXPECT_FALSE(result.get()); |
35 | 35 |
36 // Test missing instanceType element. | 36 // Test missing instanceType element. |
37 error.clear(); | 37 error.clear(); |
38 result = ContentAction::Create(*ParseJson("{}"), &error, &bad_message); | 38 result = ContentAction::Create(*ParseJson("{}"), &error, &bad_message); |
39 EXPECT_TRUE(bad_message); | 39 EXPECT_TRUE(bad_message); |
40 EXPECT_EQ("", error); | 40 EXPECT_EQ("", error); |
41 EXPECT_FALSE(result); | 41 EXPECT_FALSE(result.get()); |
42 | 42 |
43 // Test wrong instanceType element. | 43 // Test wrong instanceType element. |
44 error.clear(); | 44 error.clear(); |
45 result = ContentAction::Create(*ParseJson( | 45 result = ContentAction::Create(*ParseJson( |
46 "{\n" | 46 "{\n" |
47 " \"instanceType\": \"declarativeContent.UnknownType\",\n" | 47 " \"instanceType\": \"declarativeContent.UnknownType\",\n" |
48 "}"), | 48 "}"), |
49 &error, &bad_message); | 49 &error, &bad_message); |
50 EXPECT_THAT(error, HasSubstr("invalid instanceType")); | 50 EXPECT_THAT(error, HasSubstr("invalid instanceType")); |
51 EXPECT_FALSE(result); | 51 EXPECT_FALSE(result.get()); |
52 } | 52 } |
53 | 53 |
54 TEST(DeclarativeContentActionTest, ShowPageAction) { | 54 TEST(DeclarativeContentActionTest, ShowPageAction) { |
55 TestExtensionEnvironment env; | 55 TestExtensionEnvironment env; |
56 | 56 |
57 std::string error; | 57 std::string error; |
58 bool bad_message = false; | 58 bool bad_message = false; |
59 scoped_refptr<const ContentAction> result = ContentAction::Create( | 59 scoped_refptr<const ContentAction> result = ContentAction::Create( |
60 *ParseJson("{\n" | 60 *ParseJson("{\n" |
61 " \"instanceType\": \"declarativeContent.ShowPageAction\",\n" | 61 " \"instanceType\": \"declarativeContent.ShowPageAction\",\n" |
62 "}"), | 62 "}"), |
63 &error, &bad_message); | 63 &error, &bad_message); |
64 EXPECT_EQ("", error); | 64 EXPECT_EQ("", error); |
65 EXPECT_FALSE(bad_message); | 65 EXPECT_FALSE(bad_message); |
66 ASSERT_TRUE(result); | 66 ASSERT_TRUE(result.get()); |
67 EXPECT_EQ(ContentAction::ACTION_SHOW_PAGE_ACTION, result->GetType()); | 67 EXPECT_EQ(ContentAction::ACTION_SHOW_PAGE_ACTION, result->GetType()); |
68 | 68 |
69 const Extension* extension = env.MakeExtension( | 69 const Extension* extension = env.MakeExtension( |
70 *ParseJson("{\"page_action\": { \"default_title\": \"Extension\" } }")); | 70 *ParseJson("{\"page_action\": { \"default_title\": \"Extension\" } }")); |
71 ExtensionAction* page_action = | 71 ExtensionAction* page_action = |
72 ExtensionActionManager::Get(env.profile())->GetPageAction(*extension); | 72 ExtensionActionManager::Get(env.profile())->GetPageAction(*extension); |
73 scoped_ptr<content::WebContents> contents = env.MakeTab(); | 73 scoped_ptr<content::WebContents> contents = env.MakeTab(); |
74 const int tab_id = ExtensionTabUtil::GetTabId(contents.get()); | 74 const int tab_id = ExtensionTabUtil::GetTabId(contents.get()); |
75 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); | 75 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); |
76 ContentAction::ApplyInfo apply_info = { | 76 ContentAction::ApplyInfo apply_info = { |
77 env.profile(), contents.get() | 77 env.profile(), contents.get() |
78 }; | 78 }; |
79 result->Apply(extension->id(), base::Time(), &apply_info); | 79 result->Apply(extension->id(), base::Time(), &apply_info); |
80 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); | 80 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); |
81 result->Apply(extension->id(), base::Time(), &apply_info); | 81 result->Apply(extension->id(), base::Time(), &apply_info); |
82 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); | 82 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); |
83 result->Revert(extension->id(), base::Time(), &apply_info); | 83 result->Revert(extension->id(), base::Time(), &apply_info); |
84 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); | 84 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); |
85 result->Revert(extension->id(), base::Time(), &apply_info); | 85 result->Revert(extension->id(), base::Time(), &apply_info); |
86 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); | 86 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); |
87 } | 87 } |
88 | 88 |
89 } // namespace | 89 } // namespace |
90 } // namespace extensions | 90 } // namespace extensions |
OLD | NEW |