1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This is a gTest-based test that runs the Selenium Core testsuite in Chrome
// using the UITest automation. The number of total and failed tests are
// written to stdout.
//
// TODO(darin): output the names of the failed tests so we can easily track
// deviations from the expected output.
#include <list>
#include <set>
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/rand_util.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/window_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "net/base/net_util.h"
// Uncomment this to exercise this test without actually running the selenium
// test, which can take a while to run. This define is useful when modifying
// the analysis code.
//#define SIMULATE_RUN 1
namespace {
// This file is a comma separated list of tests that are currently failing.
const wchar_t kExpectedFailuresFileName[] = L"expected_failures.txt";
class SeleniumTest : public UITest {
public:
SeleniumTest() {
show_window_ = true;
}
typedef std::list<std::string> ResultsList;
typedef std::set<std::string> ResultsSet;
// Parses a selenium results string, which is of the form:
// "5.selectFrame,6.click,24.selectAndWait,24.verifyTitle"
void ParseResults(const std::string& input, ResultsSet* output) {
if (input.empty())
return;
std::vector<std::string> tokens;
SplitString(input, ',', &tokens);
for (size_t i = 0; i < tokens.size(); ++i) {
TrimWhitespace(tokens[i], TRIM_ALL, &tokens[i]);
output->insert(tokens[i]);
}
}
// Find the elements of "b" that are not in "a"
void CompareSets(const ResultsSet& a, const ResultsSet& b,
ResultsList* only_in_b) {
ResultsSet::const_iterator it = b.begin();
for (; it != b.end(); ++it) {
if (a.find(*it) == a.end())
only_in_b->push_back(*it);
}
}
// The results file is in trunk/chrome/test/selenium/
std::wstring GetResultsFilePath() {
std::wstring results_path;
PathService::Get(chrome::DIR_TEST_DATA, &results_path);
file_util::UpOneDirectory(&results_path);
file_util::AppendToPath(&results_path, L"selenium");
file_util::AppendToPath(&results_path, kExpectedFailuresFileName);
return results_path;
}
bool ReadExpectedResults(std::string* results) {
std::wstring results_path = GetResultsFilePath();
return file_util::ReadFileToString(results_path, results);
}
void RunSelenium(std::wstring* total, std::wstring* failed) {
#ifdef SIMULATE_RUN
*total = L"100";
const wchar_t* kBogusFailures[] = {
L"5.selectFrame,6.click,24.selectAndWait,24.verifyTitle",
L"5.selectFrame,6.click,13.verifyLocation,13.verifyLocation,13.click,24.selectAndWait,24.verifyTitle",
L"5.selectFrame,6.click,24.selectAndWait"
};
*failed = kBogusFailures[rand_util::RandInt(0, 2)];
#else
std::wstring test_path;
PathService::Get(chrome::DIR_TEST_DATA, &test_path);
file_util::UpOneDirectory(&test_path);
file_util::UpOneDirectory(&test_path);
file_util::UpOneDirectory(&test_path);
file_util::AppendToPath(&test_path, L"data");
file_util::AppendToPath(&test_path, L"selenium_core");
file_util::AppendToPath(&test_path, L"core");
file_util::AppendToPath(&test_path, L"TestRunner.html");
GURL test_url(net::FilePathToFileURL(test_path));
scoped_ptr<TabProxy> tab(GetActiveTab());
tab->NavigateToURL(test_url);
// Wait for the test to finish.
ASSERT_TRUE(WaitUntilCookieValue(tab.get(), test_url, "__tests_finished",
3000, UITest::test_timeout_ms(), "1"));
std::string cookie;
ASSERT_TRUE(tab->GetCookieByName(test_url, "__num_tests_total", &cookie));
total->swap(UTF8ToWide(cookie));
ASSERT_FALSE(total->empty());
ASSERT_TRUE(tab->GetCookieByName(test_url, "__tests_failed", &cookie));
failed->swap(UTF8ToWide(cookie));
// The __tests_failed cookie will be empty if all the tests pass.
#endif
}
void RunTest(ResultsList* new_passes_list, ResultsList* new_failures_list) {
std::string expected_failures;
bool have_expected_results = ReadExpectedResults(&expected_failures);
ASSERT_TRUE(have_expected_results);
std::wstring total, failed;
RunSelenium(&total, &failed);
if (total.empty())
return;
printf("\n");
wprintf(L"__num_tests_total = [%s]\n", total.c_str());
wprintf(L"__tests_failed = [%s]\n", failed.c_str());
std::string cur_failures = WideToUTF8(failed);
ResultsSet expected_failures_set;
ParseResults(expected_failures, &expected_failures_set);
ResultsSet cur_failures_set;
ParseResults(cur_failures, &cur_failures_set);
// Compute the list of new passes and failures
CompareSets(cur_failures_set, expected_failures_set, new_passes_list);
CompareSets(expected_failures_set, cur_failures_set, new_failures_list);
}
};
} // namespace
TEST_F(SeleniumTest, Core) {
ResultsList new_passes_list, new_failures_list;
RunTest(&new_passes_list, &new_failures_list);
if (!new_failures_list.empty()) {
ADD_FAILURE();
printf("new tests failing:\n");
ResultsList::const_iterator it = new_failures_list.begin();
for (; it != new_failures_list.end(); ++it)
printf(" %s\n", it->c_str());
printf("\n");
}
if (!new_passes_list.empty()) {
printf("new tests passing:\n");
ResultsList::const_iterator it = new_passes_list.begin();
for (; it != new_passes_list.end(); ++it)
printf(" %s\n", it->c_str());
printf("\n");
}
}
|