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

Unified Diff: chrome/browser/ui/ash/system_tray_tray_cast_browsertest_chromeos.cc

Issue 1231593002: Add some browser tests for the cast system tray. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@c0-support-code
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « a/minidump.core.out ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/ash/system_tray_tray_cast_browsertest_chromeos.cc
diff --git a/chrome/browser/ui/ash/system_tray_tray_cast_browsertest_chromeos.cc b/chrome/browser/ui/ash/system_tray_tray_cast_browsertest_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bd2d414b40658784fd914606de449742c4c6b606
--- /dev/null
+++ b/chrome/browser/ui/ash/system_tray_tray_cast_browsertest_chromeos.cc
@@ -0,0 +1,229 @@
+// Copyright 2015 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 <assert.h>
+
+#include "ash/shell.h"
+#include "ash/system/cast/tray_cast.h"
+#include "ash/system/tray/system_tray.h"
+#include "ash/system/tray/system_tray_delegate.h"
+#include "ash/system/tray/system_tray_item.h"
+#include "ash/test/tray_cast_test_api.h"
+#include "chrome/browser/extensions/extension_browsertest.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/test/test_utils.h"
+#include "extensions/browser/process_manager.h"
+
+namespace {
+
+// Execute JavaScript within the context of the extension. Returns the result
+// of the execution.
+scoped_ptr<base::Value> ExecuteJavaScript(
+ const extensions::Extension* extension,
+ const std::string& javascript) {
+ Profile* profile = ProfileManager::GetActiveUserProfile();
oshima 2015/07/21 21:21:04 GetactiveUserProfile is deprecated. Can you use m
jdufault 2015/07/21 23:50:25 Done.
jdufault 2015/07/21 23:51:59 Oops, sorry - it doesn't work here and just return
+ auto pm = extensions::ProcessManager::Get(profile);
+ content::RenderViewHost* host =
+ pm->GetBackgroundHostForExtension(extension->id())->render_view_host();
+ return content::ExecuteScriptAndGetValue(host->GetMainFrame(), javascript);
+}
+
+// Ensures that all pending JavaScript execution callbacks are invoked.
+void ExecutePendingJavaScript(const extensions::Extension* extension) {
+ ExecuteJavaScript(extension, std::string());
+}
+
+// Invokes tray->StartCast(id) and returns true if launchDesktopMirroring was
+// called with the same id. This automatically creates/destroys the detail view
+// and notifies the tray that Chrome has begun casting.
+bool StartCastWithVerification(const extensions::Extension* extension,
+ ash::TrayCast* tray,
+ const std::string& receiver_id) {
+ ash::SystemTrayItem* system_tray_item = tray;
+ ash::TrayCastTestAPI test_tray(tray);
+
+ // StartCast will simulate a button click in the detail view to begin
+ // the cast, so we need to make a detail view available.
+ system_tray_item->CreateDetailedView(ash::user::LoginStatus::LOGGED_IN_USER);
+
+ // Clear out any old state and execute any pending JS calls created from the
+ // CreateDetailedView call.
+ ExecuteJavaScript(extension, "launchDesktopMirroringReceiverId = ''");
+
+ test_tray.StartCast(receiver_id);
+
+ scoped_ptr<base::Value> get_launch_desktop_mirroring_id =
+ ExecuteJavaScript(extension, "getLaunchDesktopMirroringReceiverId()");
+ std::string result;
+ assert(get_launch_desktop_mirroring_id->GetAsString(&result));
+ system_tray_item->DestroyDetailedView();
+
+ // Tell the tray item that Chrome has started casting.
+ test_tray.OnCastingSessionStartedOrStopped(true);
+ ExecutePendingJavaScript(extension);
+
+ return receiver_id == result;
+}
+
+// Invokes tray->StopCast() and returns true if stopMirroring('user-stop')
+// was called in the extension.
+bool StopCastWithVerification(const extensions::Extension* extension,
+ ash::TrayCastTestAPI* tray) {
+ ExecuteJavaScript(extension, "stopMirroringCalled = false");
+ tray->StopCast();
+ scoped_ptr<base::Value> wasStopMirroringCalled =
+ ExecuteJavaScript(extension, "wasStopMirroringCalledWithUserStop()");
+ bool result;
+ assert(wasStopMirroringCalled->GetAsBoolean(&result));
+
+ // Tell the tray item that Chrome has stopped casting.
+ tray->OnCastingSessionStartedOrStopped(false);
+ ExecutePendingJavaScript(extension);
+
+ return result;
+}
+
+// Returns the cast tray. The tray initializer may have launched some
+// JavaScript callbacks which have not finished executing.
+ash::TrayCast* GetTrayCast(const extensions::Extension* extension) {
+ ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray();
+ // Make sure we actually popup the tray, otherwise the TrayCast instance will
+ // not be created.
+ tray->ShowDefaultView(ash::BubbleCreationType::BUBBLE_CREATE_NEW);
+
+ // Creating the tray causes some JavaScript to be executed. Let's try to make
+ // sure it is completed.
+ if (extension)
+ ExecutePendingJavaScript(extension);
+
+ return tray->GetTrayCastForTesting();
+}
+
+class SystemTrayTrayCastChromeOSTest : public ExtensionBrowserTest {
+ protected:
+ SystemTrayTrayCastChromeOSTest() : ExtensionBrowserTest() {}
+ ~SystemTrayTrayCastChromeOSTest() override {}
+
+ const extensions::Extension* LoadCastTestExtension() {
+ return LoadExtension(test_data_dir_.AppendASCII("tray_cast"));
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SystemTrayTrayCastChromeOSTest);
+};
+
+} // namespace
+
+namespace chromeos {
+
+// A simple sanity check to make sure that the cast config delegate actually
+// recognizes the cast extension.
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest,
+ CastTraySanityCheckTestExtensionGetsRecognized) {
+ ash::CastConfigDelegate* cast_config_delegate =
+ ash::Shell::GetInstance()->system_tray_delegate()->GetCastConfigDelegate();
+
+ EXPECT_FALSE(cast_config_delegate->HasCastExtension());
+ LoadCastTestExtension();
+ EXPECT_TRUE(cast_config_delegate->HasCastExtension());
+}
+
+// Verifies that the cast tray is hidden when there is no extension installed.
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest,
+ CastTrayIsHiddenWhenThereIsNoExtension) {
+ ash::TrayCastTestAPI tray(GetTrayCast(nullptr));
+ EXPECT_TRUE(tray.IsTrayInitialized());
+ EXPECT_FALSE(tray.IsTrayVisible());
+}
+
+// Verifies that the cast tray is hidden if there are no available receivers,
+// even if there is an extension installed.
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest,
+ CastTrayIsHiddenWhenThereIsAnExtensionButNoReceivers) {
+ const extensions::Extension* extension = LoadCastTestExtension();
+
+ ash::TrayCastTestAPI tray(GetTrayCast(extension));
+ EXPECT_TRUE(tray.IsTrayInitialized());
+ EXPECT_FALSE(tray.IsTrayVisible());
+}
+
+// Verifies that the cast tray is displayed when there are receivers available.
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest,
+ CastTrayIsDisplayedWhenThereIsAnExtensionWithReceivers) {
+ const extensions::Extension* extension = LoadCastTestExtension();
+ ExecuteJavaScript(extension, "addReceiver('test_id', 'name')");
+
+ ash::TrayCastTestAPI tray(GetTrayCast(extension));
+
+ EXPECT_TRUE(tray.IsTrayInitialized());
+ EXPECT_TRUE(tray.IsTrayVisible());
+}
+
+// Verifies that we can cast to a specific receiver, stop casting, and then cast
+// to another receiver when there is more than one receiver
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest,
+ CastTrayMultipleReceivers) {
+ const extensions::Extension* extension = LoadCastTestExtension();
+ ExecuteJavaScript(extension, "addReceiver('test_id_1', 'name')");
+ ExecuteJavaScript(extension, "addReceiver('not_used_0', 'name1')");
+ ExecuteJavaScript(extension, "addReceiver('test_id_0', 'name')");
+ ExecuteJavaScript(extension, "addReceiver('not_used_1', 'name2')");
+
+ ash::TrayCast* tray = GetTrayCast(extension);
+ ash::TrayCastTestAPI test_tray(tray);
+ EXPECT_TRUE(StartCastWithVerification(extension, tray, "test_id_0"));
+
+ EXPECT_TRUE(test_tray.IsTrayCastViewVisible());
+ EXPECT_TRUE(StopCastWithVerification(extension, &test_tray));
+ EXPECT_TRUE(test_tray.IsTraySelectViewVisible());
+
+ EXPECT_TRUE(StartCastWithVerification(extension, tray, "test_id_1"));
+ EXPECT_TRUE(test_tray.IsTrayCastViewVisible());
+ EXPECT_TRUE(StopCastWithVerification(extension, &test_tray));
+ EXPECT_TRUE(test_tray.IsTraySelectViewVisible());
+}
+
+// Verifies the stop cast button invokes the JavaScript function
+// "stopMirroring('user-stop')".
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest,
+ CastTrayStopButtonStopsCast) {
+ // Add a receiver that is casting.
+ const extensions::Extension* extension = LoadCastTestExtension();
+ ExecuteJavaScript(extension, "addReceiver('test_id', 'name', 'title', 1)");
+
+ ash::TrayCastTestAPI test_tray(GetTrayCast(extension));
+ test_tray.OnCastingSessionStartedOrStopped(true);
+ ExecutePendingJavaScript(extension);
+ EXPECT_TRUE(test_tray.IsTrayCastViewVisible());
+
+ // Stop the cast using the UI.
+ EXPECT_TRUE(StopCastWithVerification(extension, &test_tray));
+ EXPECT_TRUE(test_tray.IsTraySelectViewVisible());
+}
+
+// Verifies that the start cast button invokes "launchDesktopMirroring(...)".
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest,
+ CastTrayStartButtonStartsCast) {
+ const extensions::Extension* extension = LoadCastTestExtension();
+ ExecuteJavaScript(extension, "addReceiver('test_id', 'name')");
+ ash::TrayCast* tray = GetTrayCast(extension);
+ EXPECT_TRUE(StartCastWithVerification(extension, tray, "test_id"));
+}
+
+// Verifies that the CastConfigDelegate opens up a tab called "options.html".
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest, CastTrayOpenOptions) {
+ LoadCastTestExtension();
+
+ ash::CastConfigDelegate* cast_config_delegate =
+ ash::Shell::GetInstance()->system_tray_delegate()->GetCastConfigDelegate();
+ cast_config_delegate->LaunchCastOptions();
+
+ const GURL url =
+ browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
+ EXPECT_TRUE(base::StringPiece(url.GetContent()).ends_with("options.html"));
+}
+
+} // namespace chromeos
« no previous file with comments | « a/minidump.core.out ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698