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

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: Pacify clang 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 base::ListValue empty_list;
24 result = WebRequestAction::Create(empty_list, &error);
25 EXPECT_FALSE(error.empty());
26 EXPECT_FALSE(result.get());
27
28 // Test missing instanceType element.
29 base::DictionaryValue input;
30 error.clear();
31 result = WebRequestAction::Create(input, &error);
32 EXPECT_FALSE(error.empty());
33 EXPECT_FALSE(result.get());
34
35 // Test wrong instanceType element.
36 input.SetString("instanceType", kUnknownActionType);
37 error.clear();
38 result = WebRequestAction::Create(input, &error);
39 EXPECT_FALSE(error.empty());
40 EXPECT_FALSE(result.get());
41
42 // Test success
43 input.SetString("instanceType", kCancelRequestType);
44 error.clear();
45 result = WebRequestAction::Create(input, &error);
46 EXPECT_TRUE(error.empty());
47 ASSERT_TRUE(result.get());
48 EXPECT_EQ(WebRequestAction::ACTION_CANCEL_REQUEST, result->GetType());
49 }
50
51 TEST(WebRequestActionTest, CreateActionSet) {
52 std::string error;
53 scoped_ptr<WebRequestActionSet> result;
54
55 WebRequestActionSet::AnyVector input;
56
57 // Test empty input.
58 error.clear();
59 result = WebRequestActionSet::Create(input, &error);
60 EXPECT_TRUE(error.empty());
61 ASSERT_TRUE(result.get());
62 EXPECT_TRUE(result->actions().empty());
63
64 DictionaryValue correct_action;
65 correct_action.SetString("instanceType", kCancelRequestType);
66 DictionaryValue incorrect_action;
67 incorrect_action.SetString("instanceType", kUnknownActionType);
68
69 // Test success.
70 linked_ptr<json_schema_compiler::any::Any> action1 = make_linked_ptr(
71 new json_schema_compiler::any::Any);
72 action1->Init(correct_action);
73 input.push_back(action1);
74 error.clear();
75 result = WebRequestActionSet::Create(input, &error);
76 EXPECT_TRUE(error.empty());
77 ASSERT_TRUE(result.get());
78 ASSERT_EQ(1u, result->actions().size());
79 EXPECT_EQ(WebRequestAction::ACTION_CANCEL_REQUEST,
80 result->actions()[0]->GetType());
81
82 // Test failure.
83 linked_ptr<json_schema_compiler::any::Any> action2 = make_linked_ptr(
84 new json_schema_compiler::any::Any);
85 action2->Init(incorrect_action);
86 input.push_back(action2);
87 error.clear();
88 result = WebRequestActionSet::Create(input, &error);
89 EXPECT_FALSE(error.empty());
90 EXPECT_FALSE(result.get());
91 }
92
93 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698