Do not announce robot account token before account ID is available
[chromium-blink-merge.git] / chrome / test / remoting / qunit_browser_test_runner.cc
blobe476f7725dcc53355eac880962458b986afe3303
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) {
17 std::string result;
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));
24 // Read in the JSON.
25 base::JSONReader reader;
26 scoped_ptr<base::Value> value;
27 value.reset(reader.Read(result, base::JSON_ALLOW_TRAILING_COMMAS));
29 // Convert to dictionary.
30 base::DictionaryValue* dict_value = NULL;
31 ASSERT_TRUE(value->GetAsDictionary(&dict_value));
33 // Extract the fields.
34 bool passed;
35 ASSERT_TRUE(dict_value->GetBoolean("passed", &passed));
36 std::string error_message;
37 ASSERT_TRUE(dict_value->GetString("errorMessage", &error_message));
39 EXPECT_TRUE(passed) << error_message;
42 void QUnitBrowserTestRunner::RunTest(const base::FilePath& file) {
43 ASSERT_TRUE(PathExists(file)) << "Error: The QUnit test suite <"
44 << file.value() << "> does not exist.";
45 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(file));
47 content::WebContents* web_contents =
48 browser()->tab_strip_model()->GetActiveWebContents();
49 ASSERT_TRUE(web_contents);
51 std::string result;
52 QUnitStart(web_contents);