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

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 | « no previous file | 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..e246341369683fd9ba10341b6956c6c3c6afd53b
--- /dev/null
+++ b/chrome/browser/ui/ash/system_tray_tray_cast_browsertest_chromeos.cc
@@ -0,0 +1,178 @@
+// 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 "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 "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 chromeos {
+
achuithb 2015/07/08 22:04:55 remove newline
jdufault 2015/07/09 23:12:56 Done.
+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();
+ if (!profile) {
+ LOG(ERROR) << "Expected profile";
+ return nullptr;
+ }
+
+ extensions::ProcessManager* pm = extensions::ProcessManager::Get(profile);
achuithb 2015/07/08 22:04:55 You could use auto here
jdufault 2015/07/09 23:12:57 Done.
+ auto host =
achuithb 2015/07/08 22:04:55 Don't think this is appropriate since the type is
jdufault 2015/07/09 23:12:58 Done.
+ 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, "");
+}
+
+// Returns the cast tray. The tray initializer may have launched some
+// JavaScript callbacks which have not finished executing.
+ash::TrayCast* GetTrayCast() {
+ ash::Shell::GetInstance()->GetPrimarySystemTray()->ShowDefaultView(
achuithb 2015/07/08 22:04:55 I think it's worthwhile to create a temporary for
jdufault 2015/07/09 23:12:57 Done.
+ ash::BubbleCreationType::BUBBLE_CREATE_NEW);
achuithb 2015/07/08 22:04:55 What's going on here?
jdufault 2015/07/09 23:12:57 I've added a comment.
+ return ash::Shell::GetInstance()
+ ->GetPrimarySystemTray()
+ ->GetTrayCastForTesting();
+}
+
+} // namespace
+
+class SystemTrayTrayCastChromeOSTest : public ExtensionBrowserTest {
+ protected:
+ SystemTrayTrayCastChromeOSTest() : ExtensionBrowserTest() {}
+
achuithb 2015/07/08 22:04:55 remove newline?
jdufault 2015/07/09 23:12:57 Done.
+ ~SystemTrayTrayCastChromeOSTest() override {}
+
+ const extensions::Extension* LoadCastTestExtension() {
+ return LoadExtension(test_data_dir_.AppendASCII("tray_cast"));
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SystemTrayTrayCastChromeOSTest);
+};
+
+// A simple sanity check to make sure that the cast config delegate actually
+// recongnizes the cast extension.
achuithb 2015/07/08 22:04:55 sp recognizes
jdufault 2015/07/09 23:12:57 Done.
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest,
+ CastTraySanityCheckTestExtensionGetsRecognized) {
+ auto cast_config_delegate = ash::Shell::GetInstance()
achuithb 2015/07/08 22:04:55 Type is not clear
jdufault 2015/07/09 23:12:57 Done.
+ ->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::TrayCast* tray = GetTrayCast();
+ EXPECT_TRUE(tray->IsTrayInitializedForTest());
+ EXPECT_FALSE(tray->IsTrayVisibleForTest());
+}
+
+// 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) {
+ auto extension = LoadCastTestExtension();
achuithb 2015/07/08 22:04:55 Type is not clear
jdufault 2015/07/09 23:12:57 Done.
+
+ ash::TrayCast* tray = GetTrayCast();
+ ExecutePendingJavaScript(extension);
+
+ EXPECT_TRUE(tray->IsTrayInitializedForTest());
+ EXPECT_FALSE(tray->IsTrayVisibleForTest());
+}
+
+// Verifies that the cast tray is displayed when there are receivers available.
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest,
+ CastTrayIsDisplayedWhenThereIsAnExtensionWithReceivers) {
+ auto extension = LoadCastTestExtension();
achuithb 2015/07/08 22:04:55 Type is not clear.
jdufault 2015/07/09 23:12:57 Done.
+ ExecuteJavaScript(extension, "addReceiver('id', 'name', 'title', 1)");
achuithb 2015/07/08 22:04:55 test_id?
jdufault 2015/07/09 23:12:57 Done.
+
+ ash::TrayCast* tray = GetTrayCast();
+ ExecutePendingJavaScript(extension);
achuithb 2015/07/08 22:04:55 I don't understand the rationale for this sequence
jdufault 2015/07/09 23:12:57 I've modified GetTrayCast so it takes an extension
achuithb 2015/07/10 21:32:06 Yup, I like that better
+
+ EXPECT_TRUE(tray->IsTrayInitializedForTest());
+ EXPECT_TRUE(tray->IsTrayVisibleForTest());
+}
+
+// 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.
+ auto extension = LoadCastTestExtension();
achuithb 2015/07/08 22:04:55 Type is not clear
jdufault 2015/07/09 23:12:56 Done.
+ ExecuteJavaScript(extension, "addReceiver('id', 'name', 'title', 1)");
+
+ // Stop the cast using the UI.
+ ash::TrayCast* tray = GetTrayCast();
+ tray->StopCastForTest();
+ ExecutePendingJavaScript(extension);
+
+ // Verify that stopMirroring was called.
+ scoped_ptr<base::Value> wasStopMirroringCalled =
+ ExecuteJavaScript(extension, "wasStopMirroringCalledWithUserStop()");
+ bool result;
+ if (wasStopMirroringCalled->GetAsBoolean(&result) == false) {
+ FAIL(); // Unknown return type for wasStopMirroringCalled().
achuithb 2015/07/08 22:04:55 Why not EXPECT_TRUE(wasStopMirroringCalled->GetAsB
jdufault 2015/07/09 23:12:58 Done.
+ }
+ EXPECT_TRUE(result);
+}
+
+// Verifies that the start cast button invokes "launchDesktopMirroring(...)".
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest,
+ CastTrayStartButtonStartsCast) {
+ // Add a receiver.
+ auto extension = LoadCastTestExtension();
+ ExecuteJavaScript(extension, "addReceiver('id', 'name', 'title', 1)");
+
+ // Begin casting something with the id "id"
+ ash::TrayCast* tray = GetTrayCast();
+
+ // Upcast because CreateDetailedView is not visible in TrayCast
+ ((ash::SystemTrayItem*)tray)
achuithb 2015/07/08 22:04:55 Please use static_cast here
jdufault 2015/07/09 23:12:57 Done.
+ ->CreateDetailedView(ash::user::LoginStatus::LOGGED_IN_USER);
+ ExecutePendingJavaScript(extension);
+ tray->StartCastForTest("id");
achuithb 2015/07/08 22:04:55 test_id
jdufault 2015/07/09 23:12:57 Done.
+ ExecutePendingJavaScript(extension);
+
+ // Verify that launchDesktopMirroring was called with "id"
+ scoped_ptr<base::Value> launchDesktopMirroringReceiverId =
+ ExecuteJavaScript(extension, "getLaunchDesktopMirroringReceiverId()");
+ std::string result;
+ if (launchDesktopMirroringReceiverId->GetAsString(&result) == false) {
achuithb 2015/07/08 22:04:55 EXPECT_TRUE
jdufault 2015/07/09 23:12:57 Done.
+ FAIL(); // Unknown return type for launchDesktopMirroringReceiverId.
+ }
+ EXPECT_EQ("id", result);
+}
+
+IN_PROC_BROWSER_TEST_F(SystemTrayTrayCastChromeOSTest, CastTrayOpenOptions) {
+ LoadCastTestExtension();
+
+ auto cast_config_delegate = ash::Shell::GetInstance()
achuithb 2015/07/08 22:04:54 Type is not clear
jdufault 2015/07/09 23:12:57 Done.
+ ->system_tray_delegate()
+ ->GetCastConfigDelegate();
+ cast_config_delegate->LaunchCastOptions();
+
+ auto url = browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
achuithb 2015/07/08 22:04:55 GURL
jdufault 2015/07/09 23:12:57 Done.
+ EXPECT_TRUE(base::StringPiece(url.GetContent()).ends_with("options.html"));
achuithb 2015/07/08 22:04:55 Hmm, this seems a bit fragile since the cast exten
jdufault 2015/07/09 23:12:57 I'm not sure it's even a good test, because the mo
achuithb 2015/07/10 21:32:06 So the mock extension is not launching the real op
jdufault 2015/07/13 21:19:57 It's not the extension which is launching the opti
+}
+
+} // namespace chromeos
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698