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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/containers/contains.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/apps/platform_apps/app_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_profile.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/app_window/native_app_window.h"
#include "extensions/common/features/feature_channel.h"
#include "extensions/test/extension_test_message_listener.h"
#include "net/base/filename_util.h"
#include "ui/base/base_window.h"
#include "ui/gfx/geometry/rect.h"
namespace extensions {
using AppWindowApiTest = PlatformAppBrowserTest;
using ExperimentalAppWindowApiTest = ExperimentalPlatformAppBrowserTest;
// Tests chrome.app.window.setIcon.
IN_PROC_BROWSER_TEST_F(ExperimentalAppWindowApiTest, SetIcon) {
ExtensionTestMessageListener listener("ready", ReplyBehavior::kWillReply);
// Launch the app and wait for it to be ready.
LoadAndLaunchPlatformApp("windows_api_set_icon", &listener);
listener.Reply("");
AppWindow* app_window = GetFirstAppWindow();
ASSERT_TRUE(app_window);
// Now wait until the WebContent has decoded the icon and chrome has
// processed it. This needs to be in a loop since the renderer runs in a
// different process.
while (app_window->custom_app_icon().IsEmpty())
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(base::Contains(app_window->app_icon_url().spec(), "icon.png"));
}
// TODO(crbug.com/40554643): These fail on Linux with HEADLESS env var set.
#if BUILDFLAG(IS_LINUX)
#define MAYBE_OnMinimizedEvent DISABLED_OnMinimizedEvent
#define MAYBE_OnMaximizedEvent DISABLED_OnMaximizedEvent
#define MAYBE_OnRestoredEvent DISABLED_OnRestoredEvent
#else
#define MAYBE_OnMinimizedEvent OnMinimizedEvent
#define MAYBE_OnMaximizedEvent OnMaximizedEvent
#define MAYBE_OnRestoredEvent OnRestoredEvent
#endif // BUILDFLAG(IS_LINUX)
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, MAYBE_OnMinimizedEvent) {
EXPECT_TRUE(RunExtensionTest("platform_apps/windows_api_properties",
{.custom_arg = "minimized"}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, MAYBE_OnMaximizedEvent) {
EXPECT_TRUE(RunExtensionTest("platform_apps/windows_api_properties",
{.custom_arg = "maximized"}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, MAYBE_OnRestoredEvent) {
EXPECT_TRUE(RunExtensionTest("platform_apps/windows_api_properties",
{.custom_arg = "restored"}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, OnBoundsChangedEvent) {
EXPECT_TRUE(RunExtensionTest("platform_apps/windows_api_properties",
{.custom_arg = "boundsChanged"}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlwaysOnTopWithPermissions) {
EXPECT_TRUE(RunExtensionTest(
"platform_apps/windows_api_always_on_top/has_permissions",
{.launch_as_platform_app = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlwaysOnTopWithOldPermissions) {
EXPECT_TRUE(RunExtensionTest(
"platform_apps/windows_api_always_on_top/has_old_permissions",
{.launch_as_platform_app = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlwaysOnTopNoPermissions) {
EXPECT_TRUE(
RunExtensionTest("platform_apps/windows_api_always_on_top/no_permissions",
{.launch_as_platform_app = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, Get) {
EXPECT_TRUE(RunExtensionTest("platform_apps/windows_api_get",
{.launch_as_platform_app = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, SetShapeHasPerm) {
EXPECT_TRUE(RunExtensionTest("platform_apps/windows_api_shape/has_permission",
{.launch_as_platform_app = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, SetShapeNoPerm) {
EXPECT_TRUE(RunExtensionTest("platform_apps/windows_api_shape/no_permission",
{.launch_as_platform_app = true}))
<< message_;
}
// Fails on Ozone/X11. https://crbug.com/1109112
#if BUILDFLAG(IS_OZONE)
#define MAYBE_AlphaEnabledHasPermissions DISABLED_AlphaEnabledHasPermissions
#else
#define MAYBE_AlphaEnabledHasPermissions AlphaEnabledHasPermissions
#endif
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, MAYBE_AlphaEnabledHasPermissions) {
const char kNoAlphaDir[] =
"platform_apps/windows_api_alpha_enabled/has_permissions_no_alpha";
[[maybe_unused]] const char kHasAlphaDir[] =
"platform_apps/windows_api_alpha_enabled/has_permissions_has_alpha";
const char* test_dir = kNoAlphaDir;
#if defined(USE_AURA) && !BUILDFLAG(IS_LINUX)
test_dir = kHasAlphaDir;
#endif // USE_AURA && !BUILDFLAG(IS_LINUX)
EXPECT_TRUE(RunExtensionTest(test_dir, {.launch_as_platform_app = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlphaEnabledNoPermissions) {
EXPECT_TRUE(
RunExtensionTest("platform_apps/windows_api_alpha_enabled/no_permissions",
{.launch_as_platform_app = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlphaEnabledInStable) {
extensions::ScopedCurrentChannel channel(version_info::Channel::STABLE);
EXPECT_TRUE(
RunExtensionTest("platform_apps/windows_api_alpha_enabled/in_stable",
{.launch_as_platform_app = true},
// Ignore manifest warnings because the extension will
// not load at all in stable.
{.ignore_manifest_warnings = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, AlphaEnabledWrongFrameType) {
EXPECT_TRUE(RunExtensionTest(
"platform_apps/windows_api_alpha_enabled/wrong_frame_type",
{.launch_as_platform_app = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, CrossOriginIsolation) {
EXPECT_TRUE(
RunExtensionTest("platform_apps/window_api_cross_origin_isolation",
{.launch_as_platform_app = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, VisibleOnAllWorkspacesInStable) {
extensions::ScopedCurrentChannel channel(version_info::Channel::STABLE);
EXPECT_TRUE(RunExtensionTest(
"platform_apps/windows_api_visible_on_all_workspaces/in_stable",
{.launch_as_platform_app = true}))
<< message_;
}
// Tests that component extensions are allowed to open chrome:-scheme URLs in
// app windows, but not other absolute URLs.
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, OpeningAbsoluteURLs) {
base::FilePath file_path = test_data_dir_.AppendASCII("body1.html");
GURL file_url = net::FilePathToFileURL(file_path);
EXPECT_TRUE(RunExtensionTest(
"platform_apps/windows_api_opening_absolute_urls",
{.custom_arg = file_url.spec().c_str(), .launch_as_platform_app = true},
{.load_as_component = true}))
<< message_;
// The app should have successfully opened the chrome://version page.
AppWindowRegistry::AppWindowList app_windows =
AppWindowRegistry::Get(profile())->GetAppWindowsForApp(
last_loaded_extension_id());
ASSERT_EQ(1u, app_windows.size());
content::WebContents* app_window_contents =
(*app_windows.begin())->web_contents();
EXPECT_EQ(GURL("chrome://version"),
app_window_contents->GetLastCommittedURL());
EXPECT_FALSE(app_window_contents->GetPrimaryMainFrame()->IsErrorDocument());
}
#if BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, ImeWindowHasPermissions) {
EXPECT_TRUE(
RunExtensionTest("platform_apps/windows_api_ime/has_permissions_allowed",
{}, {.load_as_component = true}))
<< message_;
EXPECT_TRUE(RunExtensionTest(
"platform_apps/windows_api_ime/has_permissions_platform_app",
{.launch_as_platform_app = true}, {.ignore_manifest_warnings = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, ImeWindowNoPermissions) {
EXPECT_TRUE(
RunExtensionTest("platform_apps/windows_api_ime/no_permissions_allowed",
{}, {.load_as_component = true}))
<< message_;
EXPECT_TRUE(RunExtensionTest(
"platform_apps/windows_api_ime/no_permissions_platform_app",
{.launch_as_platform_app = true}))
<< message_;
}
IN_PROC_BROWSER_TEST_F(AppWindowApiTest, ImeWindowNotFullscreen) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitch(switches::kForceAppMode);
command_line->AppendSwitchASCII(switches::kAppId,
"jkghodnilhceideoidjikpgommlajknk");
EXPECT_TRUE(RunExtensionTest(
"platform_apps/windows_api_ime/forced_app_mode_not_fullscreen", {},
{.load_as_component = true}))
<< message_;
}
#endif // BUILDFLAG(IS_CHROMEOS)
} // namespace extensions
|