Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / media / media_browsertest.cc
blob3c7b8c932a71803294bd0f1318a2d7a60e3fe1b4
1 // Copyright 2013 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/browser/media/media_browsertest.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/public/browser/navigation_controller.h"
12 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "media/base/test_data_util.h"
16 #include "net/test/spawned_test_server/spawned_test_server.h"
18 // Common test results.
19 const char MediaBrowserTest::kEnded[] = "ENDED";
20 const char MediaBrowserTest::kError[] = "ERROR";
21 const char MediaBrowserTest::kFailed[] = "FAILED";
23 MediaBrowserTest::MediaBrowserTest() : ignore_plugin_crash_(false) {
26 MediaBrowserTest::~MediaBrowserTest() {
29 void MediaBrowserTest::RunMediaTestPage(const std::string& html_page,
30 const base::StringPairs& query_params,
31 const std::string& expected_title,
32 bool http) {
33 GURL gurl;
34 std::string query = media::GetURLQueryString(query_params);
35 scoped_ptr<net::SpawnedTestServer> http_test_server;
36 if (http) {
37 http_test_server.reset(
38 new net::SpawnedTestServer(net::SpawnedTestServer::TYPE_HTTP,
39 net::SpawnedTestServer::kLocalhost,
40 media::GetTestDataPath()));
41 CHECK(http_test_server->Start());
42 gurl = http_test_server->GetURL("files/" + html_page + "?" + query);
43 } else {
44 gurl = content::GetFileUrlWithQuery(media::GetTestDataFilePath(html_page),
45 query);
47 std::string final_title = RunTest(gurl, expected_title);
48 EXPECT_EQ(expected_title, final_title);
51 std::string MediaBrowserTest::RunTest(const GURL& gurl,
52 const std::string& expected_title) {
53 DVLOG(0) << "Running test URL: " << gurl;
54 // Observe the web contents for plugin crashes.
55 Observe(browser()->tab_strip_model()->GetActiveWebContents());
56 content::TitleWatcher title_watcher(
57 browser()->tab_strip_model()->GetActiveWebContents(),
58 base::ASCIIToUTF16(expected_title));
59 AddWaitForTitles(&title_watcher);
60 ui_test_utils::NavigateToURL(browser(), gurl);
61 base::string16 result = title_watcher.WaitAndGetTitle();
62 return base::UTF16ToASCII(result);
65 void MediaBrowserTest::AddWaitForTitles(content::TitleWatcher* title_watcher) {
66 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kEnded));
67 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kError));
68 title_watcher->AlsoWaitForTitle(base::ASCIIToUTF16(kFailed));
71 void MediaBrowserTest::PluginCrashed(const base::FilePath& plugin_path,
72 base::ProcessId plugin_pid) {
73 DVLOG(0) << "Plugin crashed: " << plugin_path.value();
74 if (ignore_plugin_crash_)
75 return;
76 ADD_FAILURE() << "Failing test due to plugin crash.";
79 void MediaBrowserTest::IgnorePluginCrash() {
80 ignore_plugin_crash_ = true;