File: autoplay_browsertest.cc

package info (click to toggle)
chromium 73.0.3683.75-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,792,156 kB
  • sloc: cpp: 13,473,466; ansic: 1,577,080; python: 898,539; javascript: 655,737; xml: 341,883; asm: 306,070; java: 289,969; perl: 80,911; objc: 67,198; sh: 43,184; cs: 27,853; makefile: 12,092; php: 11,064; yacc: 10,373; tcl: 8,875; ruby: 3,941; lex: 1,800; pascal: 1,473; lisp: 812; awk: 41; jsp: 39; sed: 19; sql: 3
file content (81 lines) | stat: -rw-r--r-- 3,076 bytes parent folder | download | duplicates (2)
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
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/ui/extensions/browser_action_test_util.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "extensions/test/result_catcher.h"
#include "extensions/test/test_extension_dir.h"
#include "media/base/media_switches.h"

class AutoplayExtensionBrowserTest : public extensions::ExtensionApiTest {
 public:
  void SetUpCommandLine(base::CommandLine* command_line) override {
    extensions::ExtensionBrowserTest::SetUpCommandLine(command_line);
    command_line->AppendSwitchASCII(
        switches::kAutoplayPolicy,
        switches::autoplay::kDocumentUserActivationRequiredPolicy);
  }
};

IN_PROC_BROWSER_TEST_F(AutoplayExtensionBrowserTest, AutoplayAllowed) {
  ASSERT_TRUE(RunExtensionTest("autoplay")) << message_;
}

IN_PROC_BROWSER_TEST_F(AutoplayExtensionBrowserTest, AutoplayAllowedInIframe) {
  ASSERT_TRUE(StartEmbeddedTestServer());

  const extensions::Extension* extension =
      LoadExtension(test_data_dir_.AppendASCII("autoplay_iframe"));
  ASSERT_TRUE(extension) << message_;

  std::unique_ptr<BrowserActionTestUtil> browser_action_test_util =
      BrowserActionTestUtil::Create(browser());
  extensions::ResultCatcher catcher;
  content::WindowedNotificationObserver popup_observer(
      content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
      content::NotificationService::AllSources());
  browser_action_test_util->Press(0);
  popup_observer.Wait();
  EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
}

IN_PROC_BROWSER_TEST_F(AutoplayExtensionBrowserTest,
                       AutoplayAllowedInHostedApp) {
  ASSERT_TRUE(StartEmbeddedTestServer());
  GURL app_url = embedded_test_server()->GetURL(
      "/extensions/autoplay_hosted_app/main.html");

  constexpr const char kHostedAppManifest[] =
      R"( { "name": "Hosted App Autoplay Test",
            "version": "1",
            "manifest_version": 2,
            "app": {
              "launch": {
                "web_url": "%s"
              }
            }
          } )";
  extensions::TestExtensionDir test_app_dir;
  test_app_dir.WriteManifest(
      base::StringPrintf(kHostedAppManifest, app_url.spec().c_str()));

  const extensions::Extension* extension =
      LoadExtension(test_app_dir.UnpackedPath());
  ASSERT_TRUE(extension) << message_;

  Browser* app_browser = LaunchAppBrowser(extension);
  content::WebContents* web_contents =
      app_browser->tab_strip_model()->GetActiveWebContents();
  EXPECT_TRUE(content::WaitForLoadStop(web_contents));

  bool result = false;
  EXPECT_TRUE(content::ExecuteScriptWithoutUserGestureAndExtractBool(
      web_contents, "runTest();", &result));
  EXPECT_TRUE(result);
}