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
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/constants/ash_features.h"
#include "ash/webui/mall/url_constants.h"
#include "ash/webui/print_preview_cros/url_constants.h"
#include "ash/webui/system_apps/public/system_web_app_type.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/ash/system_web_apps/test_support/system_web_app_integration_test.h"
#include "chromeos/constants/chromeos_features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace {
class MallAppIntegrationTest : public ash::SystemWebAppIntegrationTest {
public:
MallAppIntegrationTest() {
features_.InitWithFeatures({chromeos::features::kCrosMall},
/*disabled_features=*/{});
}
std::string GetMallEmbedUrl(content::WebContents* contents) {
// Poll to wait for an iframe to be embedded on the page, and resolve with
// the 'src' attribute.
constexpr char kScript[] = R"js(
new Promise((resolve, reject) => {
let intervalId = setInterval(() => {
const src = document.querySelector("iframe")?.src;
if (src) {
clearInterval(intervalId);
resolve(src);
}
}, 50);
});
)js";
return content::EvalJs(contents, kScript).ExtractString();
}
private:
base::test::ScopedFeatureList features_;
};
// Test that the Mall app installs and launches correctly.
IN_PROC_BROWSER_TEST_P(MallAppIntegrationTest, MallApp) {
const GURL url{ash::kChromeUIMallUrl};
EXPECT_NO_FATAL_FAILURE(ExpectSystemWebAppValid(ash::SystemWebAppType::MALL,
url,
/*title=*/"Apps & games"));
}
IN_PROC_BROWSER_TEST_P(MallAppIntegrationTest, EmbedMallWithContext) {
WaitForTestSystemAppInstall();
content::WebContents* contents = LaunchApp(ash::SystemWebAppType::MALL);
EXPECT_THAT(
GetMallEmbedUrl(contents),
testing::StartsWith(
"https://discover.apps.chrome/?origin=chrome%3A%2F%2Fmall&context="));
}
IN_PROC_BROWSER_TEST_P(MallAppIntegrationTest, EmbedMallWithDeepLink) {
WaitForTestSystemAppInstall();
apps::AppLaunchParams params =
LaunchParamsForApp(ash::SystemWebAppType::MALL);
params.override_url = GURL("chrome://mall/apps/list");
content::WebContents* contents = LaunchApp(std::move(params));
EXPECT_THAT(GetMallEmbedUrl(contents),
testing::StartsWith("https://discover.apps.chrome/apps/"
"list?origin=chrome%3A%2F%2Fmall&context="));
}
INSTANTIATE_SYSTEM_WEB_APP_MANAGER_TEST_SUITE_REGULAR_PROFILE_P(
MallAppIntegrationTest);
} // namespace
|