Chromium Code Reviews| Index: chrome/browser/extensions/api/declarative_content/content_action_unittest.cc |
| diff --git a/chrome/browser/extensions/api/declarative_content/content_action_unittest.cc b/chrome/browser/extensions/api/declarative_content/content_action_unittest.cc |
| index 6ab843c4b194538180e84b60760c27ee857ca63b..bf29bb5dfcd4372223ab480dd77bd1724fa67c5f 100644 |
| --- a/chrome/browser/extensions/api/declarative_content/content_action_unittest.cc |
| +++ b/chrome/browser/extensions/api/declarative_content/content_action_unittest.cc |
| @@ -109,5 +109,181 @@ TEST(DeclarativeContentActionTest, ShowPageAction) { |
| EXPECT_FALSE(page_action->GetIsVisible(tab_id)); |
| } |
| +TEST(DeclarativeContentActionTest, RequestContentScriptMissingScripts) { |
| + TestExtensionEnvironment env; |
| + |
| + std::string error; |
| + bool bad_message = false; |
| + scoped_refptr<const ContentAction> result = ContentAction::Create( |
| + NULL, |
| + *ParseJson( |
| + "{\n" |
| + " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" |
| + " \"allFrames\": true,\n" |
| + " \"matchAboutBlank\": true\n" |
| + "}"), |
| + &error, |
| + &bad_message); |
| + EXPECT_THAT(error, testing::HasSubstr("Missing parameter is required")); |
| + EXPECT_FALSE(bad_message); |
| + ASSERT_FALSE(result.get()); |
| +} |
| + |
| +TEST(DeclarativeContentActionTest, RequestContentScriptCSS) { |
| + TestExtensionEnvironment env; |
| + |
| + std::string error; |
| + bool bad_message = false; |
| + scoped_refptr<const ContentAction> result = ContentAction::Create( |
| + NULL, |
| + *ParseJson( |
| + "{\n" |
| + " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" |
| + " \"css\": [\"style.css\"]\n" |
| + "}"), |
| + &error, |
| + &bad_message); |
| + EXPECT_EQ("", error); |
| + EXPECT_FALSE(bad_message); |
| + ASSERT_TRUE(result.get()); |
|
Jeffrey Yasskin
2014/07/17 20:39:14
In your next patch, you should extend these to mak
Mark Dittmer
2014/07/17 23:58:14
Will do this when Apply gets implemented.
|
| + EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType()); |
| +} |
| + |
| +TEST(DeclarativeContentActionTest, RequestContentScriptJS) { |
| + TestExtensionEnvironment env; |
| + |
| + std::string error; |
| + bool bad_message = false; |
| + scoped_refptr<const ContentAction> result = ContentAction::Create( |
| + NULL, |
| + *ParseJson( |
| + "{\n" |
| + " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" |
| + " \"js\": [\"script.js\"]\n" |
| + "}"), |
| + &error, |
| + &bad_message); |
| + EXPECT_EQ("", error); |
| + EXPECT_FALSE(bad_message); |
| + ASSERT_TRUE(result.get()); |
| + EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType()); |
| +} |
| + |
| +TEST(DeclarativeContentActionTest, RequestContentScriptCSSBadType) { |
| + TestExtensionEnvironment env; |
| + |
| + std::string error; |
| + bool bad_message = false; |
| + scoped_refptr<const ContentAction> result = ContentAction::Create( |
| + NULL, |
| + *ParseJson( |
| + "{\n" |
| + " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" |
| + " \"css\": \"style.css\"\n" |
| + "}"), |
| + &error, |
| + &bad_message); |
| + EXPECT_TRUE(bad_message); |
| + ASSERT_FALSE(result.get()); |
| +} |
| + |
| +TEST(DeclarativeContentActionTest, RequestContentScriptJSBadType) { |
| + TestExtensionEnvironment env; |
| + |
| + std::string error; |
| + bool bad_message = false; |
| + scoped_refptr<const ContentAction> result = ContentAction::Create( |
| + NULL, |
| + *ParseJson( |
| + "{\n" |
| + " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" |
| + " \"js\": \"script.js\"\n" |
| + "}"), |
| + &error, |
| + &bad_message); |
| + EXPECT_TRUE(bad_message); |
| + ASSERT_FALSE(result.get()); |
| +} |
| + |
| +TEST(DeclarativeContentActionTest, RequestContentScriptAllFrames) { |
| + TestExtensionEnvironment env; |
| + |
| + std::string error; |
| + bool bad_message = false; |
| + scoped_refptr<const ContentAction> result = ContentAction::Create( |
| + NULL, |
| + *ParseJson( |
| + "{\n" |
| + " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" |
| + " \"js\": [\"script.js\"],\n" |
| + " \"allFrames\": true\n" |
| + "}"), |
| + &error, |
| + &bad_message); |
| + EXPECT_EQ("", error); |
| + EXPECT_FALSE(bad_message); |
| + ASSERT_TRUE(result.get()); |
| + EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType()); |
| +} |
| + |
| +TEST(DeclarativeContentActionTest, RequestContentScriptMatchAboutBlank) { |
| + TestExtensionEnvironment env; |
| + |
| + std::string error; |
| + bool bad_message = false; |
| + scoped_refptr<const ContentAction> result = ContentAction::Create( |
| + NULL, |
| + *ParseJson( |
| + "{\n" |
| + " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" |
| + " \"js\": [\"script.js\"],\n" |
| + " \"matchAboutBlank\": true\n" |
| + "}"), |
| + &error, |
| + &bad_message); |
| + EXPECT_EQ("", error); |
| + EXPECT_FALSE(bad_message); |
| + ASSERT_TRUE(result.get()); |
| + EXPECT_EQ(ContentAction::ACTION_REQUEST_CONTENT_SCRIPT, result->GetType()); |
| +} |
| + |
| +TEST(DeclarativeContentActionTest, RequestContentScriptAllFramesBadType) { |
| + TestExtensionEnvironment env; |
| + |
| + std::string error; |
| + bool bad_message = false; |
| + scoped_refptr<const ContentAction> result = ContentAction::Create( |
| + NULL, |
| + *ParseJson( |
| + "{\n" |
| + " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" |
| + " \"js\": [\"script.js\"],\n" |
| + " \"allFrames\": null\n" |
| + "}"), |
| + &error, |
| + &bad_message); |
| + EXPECT_TRUE(bad_message); |
| + ASSERT_FALSE(result.get()); |
| +} |
| + |
| +TEST(DeclarativeContentActionTest, RequestContentScriptMatchAboutBlankBadType) { |
| + TestExtensionEnvironment env; |
| + |
| + std::string error; |
| + bool bad_message = false; |
| + scoped_refptr<const ContentAction> result = ContentAction::Create( |
| + NULL, |
| + *ParseJson( |
| + "{\n" |
| + " \"instanceType\": \"declarativeContent.RequestContentScript\",\n" |
| + " \"js\": [\"script.js\"],\n" |
| + " \"matchAboutBlank\": null\n" |
| + "}"), |
| + &error, |
| + &bad_message); |
| + EXPECT_TRUE(bad_message); |
| + ASSERT_FALSE(result.get()); |
| +} |
| + |
| } // namespace |
| } // namespace extensions |