| Index: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc
|
| index e594b930908fac0a1889e3462f0c8f4e910ffbbc..bbcfc0783e067b6b7cd3e0727840981a70737819 100644
|
| --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc
|
| +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc
|
| @@ -7,6 +7,7 @@
|
| #include "base/message_loop.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_constants.h"
|
| +#include "content/public/browser/resource_request_info.h"
|
| #include "net/url_request/url_request_test_util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -24,35 +25,57 @@ TEST(WebRequestConditionAttributeTest, CreateConditionAttribute) {
|
|
|
| std::string error;
|
| scoped_ptr<WebRequestConditionAttribute> result;
|
| - StringValue http_string_value("http");
|
| - ListValue list_value;
|
| + StringValue string_value("main_frame");
|
| + ListValue resource_types;
|
| + resource_types.Append(Value::CreateStringValue("main_frame"));
|
|
|
| // Test wrong condition name passed.
|
| error.clear();
|
| result = WebRequestConditionAttribute::Create(
|
| - kUnknownConditionName, &http_string_value, &error);
|
| + kUnknownConditionName, &resource_types, &error);
|
| EXPECT_FALSE(error.empty());
|
| EXPECT_FALSE(result.get());
|
|
|
| // Test wrong data type passed
|
| error.clear();
|
| result = WebRequestConditionAttribute::Create(
|
| - kUnknownConditionName, &list_value, &error);
|
| + keys::kResourceTypeKey, &string_value, &error);
|
| EXPECT_FALSE(error.empty());
|
| EXPECT_FALSE(result.get());
|
|
|
| // Test success
|
| error.clear();
|
| result = WebRequestConditionAttribute::Create(
|
| - keys::kSchemeKey, &http_string_value, &error);
|
| - EXPECT_TRUE(error.empty());
|
| + keys::kResourceTypeKey, &resource_types, &error);
|
| + EXPECT_EQ("", error);
|
| ASSERT_TRUE(result.get());
|
| - EXPECT_EQ(WebRequestConditionAttribute::CONDITION_HAS_SCHEME,
|
| + EXPECT_EQ(WebRequestConditionAttribute::CONDITION_RESOURCE_TYPE,
|
| result->GetType());
|
| +}
|
| +
|
| +TEST(WebRequestConditionAttributeTest, TestResourceType) {
|
| + // Necessary for TestURLRequest.
|
| + MessageLoop message_loop(MessageLoop::TYPE_IO);
|
| +
|
| + std::string error;
|
| + ListValue resource_types;
|
| + resource_types.Append(Value::CreateStringValue("main_frame"));
|
| +
|
| + scoped_ptr<WebRequestConditionAttribute> attribute =
|
| + WebRequestConditionAttribute::Create(
|
| + keys::kResourceTypeKey, &resource_types, &error);
|
| + EXPECT_EQ("", error);
|
| + ASSERT_TRUE(attribute.get());
|
| +
|
| TestURLRequest url_request_ok(GURL("http://www.example.com"), NULL);
|
| - EXPECT_TRUE(result->IsFulfilled(&url_request_ok, ON_BEFORE_REQUEST));
|
| - TestURLRequest url_request_fail(GURL("https://www.example.com"), NULL);
|
| - EXPECT_FALSE(result->IsFulfilled(&url_request_fail, ON_BEFORE_REQUEST));
|
| + content::ResourceRequestInfo::AllocateForTesting(&url_request_ok,
|
| + ResourceType::MAIN_FRAME, NULL);
|
| + EXPECT_TRUE(attribute->IsFulfilled(&url_request_ok, ON_BEFORE_REQUEST));
|
| +
|
| + TestURLRequest url_request_fail(GURL("http://www.example.com"), NULL);
|
| + content::ResourceRequestInfo::AllocateForTesting(&url_request_ok,
|
| + ResourceType::SUB_FRAME, NULL);
|
| + EXPECT_FALSE(attribute->IsFulfilled(&url_request_fail, ON_BEFORE_REQUEST));
|
| }
|
|
|
| } // namespace extensions
|
|
|