1 // Copyright 2014 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.
5 #include "chrome/test/remoting/qunit_browser_test_runner.h"
7 #include "base/files/file_util.h"
8 #include "base/json/json_reader.h"
9 #include "base/values.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "content/public/test/browser_test_utils.h"
14 #include "net/base/filename_util.h"
16 void QUnitBrowserTestRunner::QUnitStart(content::WebContents
* web_contents
) {
19 // The test suite must include /third_party/qunit/src/browser_test_harness.js
20 // which exposes the entry point browserTestHarness.run().
21 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
22 web_contents
, "browserTestHarness.run();", &result
));
25 scoped_ptr
<base::Value
> value
= base::JSONReader::Read(
26 result
, base::JSON_ALLOW_TRAILING_COMMAS
);
28 // Convert to dictionary.
29 base::DictionaryValue
* dict_value
= NULL
;
30 ASSERT_TRUE(value
->GetAsDictionary(&dict_value
));
32 // Extract the fields.
34 ASSERT_TRUE(dict_value
->GetBoolean("passed", &passed
));
35 std::string error_message
;
36 ASSERT_TRUE(dict_value
->GetString("errorMessage", &error_message
));
38 EXPECT_TRUE(passed
) << error_message
;
41 void QUnitBrowserTestRunner::RunTest(const base::FilePath
& file
) {
42 ASSERT_TRUE(PathExists(file
)) << "Error: The QUnit test suite <"
43 << file
.value() << "> does not exist.";
44 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(file
));
46 content::WebContents
* web_contents
=
47 browser()->tab_strip_model()->GetActiveWebContents();
48 ASSERT_TRUE(web_contents
);
51 QUnitStart(web_contents
);