Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_action_unittest.cc

Issue 9820003: Implementation of beginning of Declarative Web Request API backend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_action .h"
6
7 #include "base/values.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace {
11 const char kCancelRequestType[] = "experimental.webRequest.CancelRequest";
12 const char kUnknownActionType[] = "unknownType";
13 } // namespace
14
15 namespace extensions {
16
17 TEST(WebRequestActionTest, CreateAction) {
18 std::string error;
19 scoped_ptr<WebRequestAction> result;
20
21 // Test wrong data type passed.
22 error.clear();
23 result = WebRequestAction::Create(base::ListValue(), &error);
24 EXPECT_FALSE(error.empty());
25 EXPECT_FALSE(result.get());
26
27 // Test missing instanceType element.
28 base::DictionaryValue input;
29 error.clear();
30 result = WebRequestAction::Create(input, &error);
31 EXPECT_FALSE(error.empty());
32 EXPECT_FALSE(result.get());
33
34 // Test wrong instanceType element.
35 input.SetString("instanceType", kUnknownActionType);
36 error.clear();
37 result = WebRequestAction::Create(input, &error);
38 EXPECT_FALSE(error.empty());
39 EXPECT_FALSE(result.get());
40
41 // Test success
42 input.SetString("instanceType", kCancelRequestType);
43 error.clear();
44 result = WebRequestAction::Create(input, &error);
45 EXPECT_TRUE(error.empty());
46 ASSERT_TRUE(result.get());
47 EXPECT_EQ(WebRequestAction::ACTION_CANCEL_REQUEST, result->type());
48 }
49
50 TEST(WebRequestActionTest, CreateActionCollection) {
51 std::string error;
52 scoped_ptr<WebRequestActionCollection> result;
53
54 WebRequestActionCollection::AnyVector input;
55
56 // Test empty input.
57 error.clear();
58 result = WebRequestActionCollection::Create(input, &error);
59 EXPECT_TRUE(error.empty());
60 ASSERT_TRUE(result.get());
61 EXPECT_TRUE(result->actions().empty());
62
63 DictionaryValue correct_action;
64 correct_action.SetString("instanceType", kCancelRequestType);
65 DictionaryValue incorrect_action;
66 incorrect_action.SetString("instanceType", kUnknownActionType);
67
68 // Test success.
69 linked_ptr<json_schema_compiler::any::Any> action1 = make_linked_ptr(
70 new json_schema_compiler::any::Any);
71 action1->Init(correct_action);
72 input.push_back(action1);
73 error.clear();
74 result = WebRequestActionCollection::Create(input, &error);
75 EXPECT_TRUE(error.empty());
76 ASSERT_TRUE(result.get());
77 ASSERT_EQ(1u, result->actions().size());
78 EXPECT_EQ(WebRequestAction::ACTION_CANCEL_REQUEST,
79 result->actions()[0]->type());
80
81 // Test failure.
82 linked_ptr<json_schema_compiler::any::Any> action2 = make_linked_ptr(
83 new json_schema_compiler::any::Any);
84 action2->Init(incorrect_action);
85 input.push_back(action2);
86 error.clear();
87 result = WebRequestActionCollection::Create(input, &error);
88 EXPECT_FALSE(error.empty());
89 EXPECT_FALSE(result.get());
90 }
91
92 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698