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

Side by Side Diff: chrome/test/media_router/media_router_integration_browsertest.cc

Issue 595663002: Put chromoting isolate targets under chromoting_swarm_tests=1 GYP variable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2015 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/test/media_router/media_router_integration_browsertest.h"
6
7 #include "base/files/file_util.h"
8 #include "base/json/json_reader.h"
9 #include "base/path_service.h"
10 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller.h"
15 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/public/test/browser_test_utils.h"
17 #include "content/public/test/test_navigation_observer.h"
18 #include "content/public/test/test_utils.h"
19 #include "net/base/filename_util.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace media_router {
23
24 MediaRouterIntegrationBrowserTest::MediaRouterIntegrationBrowserTest() {
25 }
26
27 MediaRouterIntegrationBrowserTest::~MediaRouterIntegrationBrowserTest() {
28 }
29
30 void MediaRouterIntegrationBrowserTest::ExecuteJavaScriptAPI(
31 content::WebContents* web_contents,
32 const std::string& script) {
33 std::string result;
34
35 ASSERT_TRUE(
36 content::ExecuteScriptAndExtractString(web_contents, script, &result));
37
38 // Read the test result, the test result set by javascript is a
39 // JSON string with the following format:
40 // {"passed": "<true/false>", "errorMessage": "<error_message>"}
41 scoped_ptr<base::Value> value = base::JSONReader::Read(
42 result, base::JSON_ALLOW_TRAILING_COMMAS);
43
44 // Convert to dictionary.
45 base::DictionaryValue* dict_value = nullptr;
46 ASSERT_TRUE(value->GetAsDictionary(&dict_value));
47
48 // Extract the fields.
49 bool passed = false;
50 ASSERT_TRUE(dict_value->GetBoolean("passed", &passed));
51 std::string error_message;
52 ASSERT_TRUE(dict_value->GetString("errorMessage", &error_message));
53
54 EXPECT_TRUE(passed) << error_message;
55 }
56
57 void MediaRouterIntegrationBrowserTest::OpenTestPage(
58 const std::string& file_name) {
59 base::FilePath base_dir;
60 ASSERT_TRUE(PathService::Get(base::DIR_EXE, &base_dir));
61 base::FilePath full_path = base_dir.Append(
62 FILE_PATH_LITERAL("media_router/browser_test_resources/" + file_name));
63 ASSERT_TRUE(PathExists(full_path));
64 ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(full_path));
65 }
66
67 void MediaRouterIntegrationBrowserTest::ChooseSink(
68 content::WebContents* web_contents,
69 const std::string& sink_id) {
70 MediaRouterDialogController* controller =
71 MediaRouterDialogController::GetOrCreateForWebContents(web_contents);
72 content::WebContents* dialog_contents = controller->GetMediaRouterDialog();
73 ASSERT_TRUE(dialog_contents);
74 std::string script = base::StringPrintf(
75 "window.document.getElementById('media-router-container')."
76 "showOrCreateRoute_({'id': '%s', 'name': ''}, null)",
77 sink_id.c_str());
78 ASSERT_TRUE(content::ExecuteScript(dialog_contents, script));
79 }
80
81 // TODO(leilei): Enable this test case once the buildbot is updated.
82 // To make it pass on buildbot, we need to run browser tests after download
83 // media router dev extension.
84 IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MANUAL_Basic) {
85 OpenTestPage("basic_test.html");
86 content::WebContents* web_contents =
87 browser()->tab_strip_model()->GetActiveWebContents();
88 ASSERT_TRUE(web_contents);
89 content::TestNavigationObserver test_navigation_observer(web_contents, 1);
90 test_navigation_observer.StartWatchingNewWebContents();
91 ExecuteJavaScriptAPI(web_contents, "startSession();");
92 test_navigation_observer.Wait();
93 ChooseSink(web_contents, "id1");
94 ExecuteJavaScriptAPI(web_contents, "checkSession();");
95 Wait(base::TimeDelta::FromSeconds(5));
96 ExecuteJavaScriptAPI(web_contents, "stopSession();");
97 }
98
99 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/test/media_router/media_router_integration_browsertest.h ('k') | chrome/test/media_router/media_router_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698