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

Side by Side Diff: chrome/test/chromedriver/chrome_impl_unittest.cc

Issue 12848005: [chromedriver] Separate stuff of chrome from chromedriver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments and fix compile error on mac. Created 7 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 <list>
6 #include <string>
7
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h"
11 #include "chrome/test/chromedriver/chrome_impl.h"
12 #include "chrome/test/chromedriver/devtools_client.h"
13 #include "chrome/test/chromedriver/status.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace {
17
18 typedef std::list<internal::WebViewInfo> WebViewInfoList;
19
20 void ExpectEqual(const internal::WebViewInfo& info1,
21 const internal::WebViewInfo& info2) {
22 EXPECT_EQ(info1.id, info2.id);
23 EXPECT_EQ(info1.type, info2.type);
24 EXPECT_EQ(info1.url, info2.url);
25 EXPECT_EQ(info1.debugger_url, info2.debugger_url);
26 }
27
28 } // namespace
29
30 TEST(ParsePagesInfo, Normal) {
31 WebViewInfoList list;
32 Status status = internal::ParsePagesInfo(
33 "[{\"type\": \"page\", \"id\": \"1\", \"url\": \"http://page1\","
34 " \"webSocketDebuggerUrl\": \"ws://debugurl1\"}]",
35 &list);
36 ASSERT_TRUE(status.IsOk());
37 ASSERT_EQ(1u, list.size());
38 ExpectEqual(
39 internal::WebViewInfo(
40 "1", "ws://debugurl1", "http://page1", internal::WebViewInfo::kPage),
41 list.front());
42 }
43
44 TEST(ParsePagesInfo, Multiple) {
45 WebViewInfoList list;
46 Status status = internal::ParsePagesInfo(
47 "[{\"type\": \"page\", \"id\": \"1\", \"url\": \"http://page1\","
48 " \"webSocketDebuggerUrl\": \"ws://debugurl1\"},"
49 " {\"type\": \"other\", \"id\": \"2\", \"url\": \"http://page2\","
50 " \"webSocketDebuggerUrl\": \"ws://debugurl2\"}]",
51 &list);
52 ASSERT_TRUE(status.IsOk());
53 ASSERT_EQ(2u, list.size());
54 ExpectEqual(
55 internal::WebViewInfo(
56 "1", "ws://debugurl1", "http://page1", internal::WebViewInfo::kPage),
57 list.front());
58 ExpectEqual(
59 internal::WebViewInfo(
60 "2", "ws://debugurl2", "http://page2", internal::WebViewInfo::kOther),
61 list.back());
62 }
63
64 TEST(ParsePagesInfo, WithoutDebuggerUrl) {
65 WebViewInfoList list;
66 Status status = internal::ParsePagesInfo(
67 "[{\"type\": \"page\", \"id\": \"1\", \"url\": \"http://page1\"}]",
68 &list);
69 ASSERT_TRUE(status.IsOk());
70 ASSERT_EQ(1u, list.size());
71 ExpectEqual(
72 internal::WebViewInfo(
73 "1", "", "http://page1", internal::WebViewInfo::kPage),
74 list.front());
75 }
76
77 namespace {
78
79 void AssertFails(const std::string& data) {
80 WebViewInfoList list;
81 Status status = internal::ParsePagesInfo(data, &list);
82 ASSERT_FALSE(status.IsOk());
83 ASSERT_EQ(0u, list.size());
84 }
85
86 } // namespace
87
88 TEST(ParsePagesInfo, NonList) {
89 AssertFails("{\"id\": \"1\"}");
90 }
91
92 TEST(ParsePagesInfo, NonDictionary) {
93 AssertFails("[1]");
94 }
95
96 TEST(ParsePagesInfo, NoId) {
97 AssertFails(
98 "[{\"type\": \"page\", \"url\": \"http://page1\","
99 " \"webSocketDebuggerUrl\": \"ws://debugurl1\"}]");
100 }
101
102 TEST(ParsePagesInfo, InvalidId) {
103 AssertFails(
104 "[{\"type\": \"page\", \"id\": 1, \"url\": \"http://page1\","
105 " \"webSocketDebuggerUrl\": \"ws://debugurl1\"}]");
106 }
107
108 TEST(ParsePagesInfo, NoType) {
109 AssertFails(
110 "[{\"id\": \"1\", \"url\": \"http://page1\","
111 " \"webSocketDebuggerUrl\": \"ws://debugurl1\"}]");
112 }
113
114 TEST(ParsePagesInfo, InvalidType) {
115 AssertFails(
116 "[{\"type\": \"123\", \"id\": \"1\", \"url\": \"http://page1\","
117 " \"webSocketDebuggerUrl\": \"ws://debugurl1\"}]");
118 }
119
120 TEST(ParsePagesInfo, NoUrl) {
121 AssertFails(
122 "[{\"type\": \"page\", \"id\": \"1\","
123 " \"webSocketDebuggerUrl\": \"ws://debugurl1\"}]");
124 }
125
126 TEST(ParsePagesInfo, InvalidUrl) {
127 AssertFails(
128 "[{\"type\": \"page\", \"id\": \"1\", \"url\": 1,"
129 " \"webSocketDebuggerUrl\": \"ws://debugurl1\"}]");
130 }
131
132 namespace {
133
134 void AssertVersionFails(const std::string& data) {
135 std::string version;
136 Status status = internal::ParseVersionInfo(data, &version);
137 ASSERT_TRUE(status.IsError());
138 ASSERT_TRUE(version.empty());
139 }
140
141 } // namespace
142
143 TEST(ParseVersionInfo, InvalidJSON) {
144 AssertVersionFails("[");
145 }
146
147 TEST(ParseVersionInfo, NonDict) {
148 AssertVersionFails("[]");
149 }
150
151 TEST(ParseVersionInfo, NoBrowserKey) {
152 AssertVersionFails("{}");
153 }
154
155 TEST(ParseVersionInfo, Valid) {
156 std::string version;
157 Status status = internal::ParseVersionInfo("{\"Browser\": \"1\"}", &version);
158 ASSERT_TRUE(status.IsOk());
159 ASSERT_EQ("1", version);
160 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/chrome_impl.cc ('k') | chrome/test/chromedriver/chrome_launcher_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698