0

Make xr_browser_tests more platform agnostic

Updates code that relied on XrBrowserTests being based off of
InProcessBrowserTest and/or other outdated windows-only assumptions to
use more cross-platform available solutions, so that the code can be
built into android_browsertests.

Note that there is still quite a lot of backend implementation for
OpenXR that is windows-specific, this is mainly just some isolated
bits that required cross-platform refactoring and thus the bulk of what
I would expect to potentially impact test stability/passing that seemed
better served by being split out.

Bug: 40904930
Change-Id: I2f0272096cbeec7d6d65b1f67be604b42f5f0e43
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5538981
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1301642}
This commit is contained in:
Alexander Cooper
2024-05-15 23:07:13 +00:00
committed by Chromium LUCI CQ
parent cc04eb8474
commit 14472195fc
7 changed files with 70 additions and 51 deletions

@ -58,8 +58,7 @@
#define DEFINE_INCOGNITO_BROWSER_TEST_(test_class, test_name) \
IN_PROC_BROWSER_TEST_F(test_class, test_name##Incognito) { \
auto* browser = CreateIncognitoBrowser(); \
SetBrowser(browser); \
SetIncognito(); \
MULTI_CLASS_RUNNER_NAME_(test_name)::ActuallyRunTestOnMainThread(this); \
}

@ -9,9 +9,7 @@
#include "base/task/single_thread_task_runner.h"
#include "base/threading/platform_thread.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_WIN)
#include "chrome/browser/vr/vr_browser_renderer_thread.h"
#endif // BUILDFLAG(IS_WIN)
#include "chrome/browser/vr/test/xr_browser_test.h"
namespace vr {
@ -93,31 +91,19 @@ void UiUtils::WatchElementForVisibilityStatusForTesting(
}
void UiUtils::DisableOverlayForTesting() {
#if BUILDFLAG(IS_WIN)
VRBrowserRendererThread::DisableOverlayForTesting();
#else
NOTREACHED_IN_MIGRATION();
#endif // BUILDFLAG(IS_WIN)
}
VRBrowserRendererThread* UiUtils::GetRendererThread() {
#if BUILDFLAG(IS_WIN)
return VRBrowserRendererThread::GetInstanceForTesting();
#else
NOTREACHED_IN_MIGRATION();
#endif // BUILDFLAG(IS_WIN)
}
BrowserRenderer* UiUtils::GetBrowserRenderer() {
#if BUILDFLAG(IS_WIN)
auto* renderer_thread = GetRendererThread();
if (renderer_thread == nullptr)
return nullptr;
return static_cast<VRBrowserRendererThread*>(renderer_thread)
->GetBrowserRendererForTesting();
#else
NOTREACHED_IN_MIGRATION();
#endif // BUILDFLAG(IS_WIN)
}
} // namespace vr

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/vr/test/xr_browser_test.h"
#include <cstring>
#include "base/base_paths.h"
@ -18,17 +20,20 @@
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/vr/test/xr_browser_test.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/base/chrome_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_ANDROID)
#else
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#endif
namespace vr {
constexpr base::TimeDelta XrBrowserTestBase::kPollCheckIntervalShort;
@ -143,7 +148,7 @@ void XrBrowserTestBase::SetUp() {
scoped_feature_list_.InitWithFeatures(enable_features_, disable_features_);
InProcessBrowserTest::SetUp();
PlatformBrowserTest::SetUp();
}
void XrBrowserTestBase::TearDown() {
@ -152,7 +157,7 @@ void XrBrowserTestBase::TearDown() {
// so can result in hitting a DCHECK.
return;
}
InProcessBrowserTest::TearDown();
PlatformBrowserTest::TearDown();
}
XrBrowserTestBase::RuntimeType XrBrowserTestBase::GetRuntimeType() const {
@ -178,13 +183,47 @@ net::EmbeddedTestServer* XrBrowserTestBase::GetEmbeddedServer() {
}
content::WebContents* XrBrowserTestBase::GetCurrentWebContents() {
return browser()->tab_strip_model()->GetActiveWebContents();
#if !BUILDFLAG(IS_ANDROID)
// `chrome_test_utils::GetActiveWebContents()` doesn't properly account for
// the presence of an incognito browser, and only looks in the browser
// returned by the base class, which doesn't get overridden by the incognito
// browser.
if (incognito_) {
Browser* incognito_browser = chrome::FindTabbedBrowser(
browser()->profile()->GetPrimaryOTRProfile(/*create_if_needed=*/false),
/*match_original_profiles=*/false);
return incognito_browser->tab_strip_model()->GetActiveWebContents();
}
#endif
return chrome_test_utils::GetActiveWebContents(this);
}
void XrBrowserTestBase::SetIncognito() {
incognito_ = true;
OpenNewTab(url::kAboutBlankURL);
}
void XrBrowserTestBase::OpenNewTab(const std::string& url) {
OpenNewTab(url, incognito_);
}
void XrBrowserTestBase::OpenNewTab(const std::string& url, bool incognito) {
#if BUILDFLAG(IS_ANDROID)
NOTREACHED_NORETURN();
#else
if (incognito) {
OpenURLOffTheRecord(browser()->profile(), GURL(url));
} else {
// -1 is a special index value used to append to the end of the tab list.
chrome::AddTabAt(browser(), GURL(url), /*index=*/-1, /*foreground=*/true);
}
#endif
}
void XrBrowserTestBase::LoadFileAndAwaitInitialization(
const std::string& test_name) {
GURL url = GetUrlForFile(test_name);
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
ASSERT_TRUE(content::NavigateToURL(GetCurrentWebContents(), url));
ASSERT_TRUE(PollJavaScriptBoolean("isInitializationComplete()",
kPollTimeoutMedium,
GetCurrentWebContents()))

@ -14,9 +14,7 @@
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/vr/test/conditional_skipping.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "device/vr/public/cpp/features.h"
#include "device/vr/test/test_hook.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
@ -25,6 +23,11 @@
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#endif
#if BUILDFLAG(IS_ANDROID)
#include "chrome/test/base/android/android_browser_test.h"
#else // !IS_ANDROID
#include "chrome/test/base/in_process_browser_test.h"
#endif
namespace content {
class WebContents;
@ -37,7 +40,7 @@ namespace vr {
// //chrome/android/javatests/src/.../browser/vr/XrTestFramework.java
// This must be subclassed for different XR features to handle the differences
// between APIs and different usecases of the same API.
class XrBrowserTestBase : public InProcessBrowserTest {
class XrBrowserTestBase : public PlatformBrowserTest {
public:
static constexpr base::TimeDelta kPollCheckIntervalShort =
base::Milliseconds(50);
@ -148,16 +151,10 @@ class XrBrowserTestBase : public InProcessBrowserTest {
// JavaScript errors were encountered.
void AssertNoJavaScriptErrors(content::WebContents* web_contents);
Browser* browser() {
return browser_ == nullptr ? InProcessBrowserTest::browser()
: browser_.get();
}
void SetIncognito();
void SetBrowser(Browser* browser) { browser_ = browser; }
Browser* CreateIncognitoBrowser(Profile* profile = nullptr) {
return InProcessBrowserTest::CreateIncognitoBrowser(profile);
}
void OpenNewTab(const std::string& url);
void OpenNewTab(const std::string& url, bool incognito);
// Convenience function for running RunJavaScriptOrFail with the return value
// of GetCurrentWebContents.
@ -230,11 +227,11 @@ class XrBrowserTestBase : public InProcessBrowserTest {
// HTML files, initializing and starting the server if necessary.
net::EmbeddedTestServer* GetEmbeddedServer();
raw_ptr<Browser, AcrossTasksDanglingUntriaged> browser_ = nullptr;
std::unique_ptr<net::EmbeddedTestServer> server_;
base::test::ScopedFeatureList scoped_feature_list_;
bool test_skipped_at_startup_ = false;
bool javascript_failed_ = false;
bool incognito_ = false;
};
} // namespace vr

@ -5,7 +5,6 @@
#include "build/build_config.h"
#include "chrome/browser/vr/test/webxr_vr_browser_test.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
namespace vr {
@ -13,7 +12,7 @@ namespace vr {
// are no runtimes available.
IN_PROC_BROWSER_TEST_F(WebXrVrRuntimelessBrowserTest,
TestInlineIdentityAlwaysAvailable) {
browser()->tab_strip_model()->GetActiveWebContents()->Focus();
GetCurrentWebContents()->Focus();
LoadFileAndAwaitInitialization("test_inline_viewer_available");
WaitOnJavaScriptStep();
EndTest();

@ -2,16 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/vr/test/multi_class_browser_test.h"
#include "chrome/browser/vr/test/webxr_vr_browser_test.h"
#include "url/gurl.h"
#include "url/url_constants.h"
// Browser test equivalent of
// chrome/android/javatests/src/.../browser/vr/WebXrVrTabTest.java.
// End-to-end tests for testing WebXR's interaction with multiple tabs.
namespace vr {
// Tests that non-focused tabs cannot get pose information from WebXR.
@ -20,8 +17,7 @@ void TestPoseDataUnfocusedTabImpl(WebXrVrBrowserTestBase* t,
t->LoadFileAndAwaitInitialization(filename);
t->ExecuteStepAndWait("stepCheckFrameDataWhileFocusedTab()");
auto* first_tab_web_contents = t->GetCurrentWebContents();
chrome::AddTabAt(t->browser(), GURL(url::kAboutBlankURL),
-1 /* index, append to end */, true /* foreground */);
t->OpenNewTab(url::kAboutBlankURL);
t->ExecuteStepAndWait("stepCheckFrameDataWhileNonFocusedTab()",
first_tab_web_contents);
t->EndTest(first_tab_web_contents);

@ -477,11 +477,13 @@ XrResult xrEnumerateInstanceExtensionProperties(
RETURN_IF(properties == nullptr, XR_ERROR_VALIDATION_FAILURE,
"XrExtensionProperties is nullptr");
for (uint32_t i = 0; i < OpenXrTestHelper::kNumExtensionsSupported; i++) {
size_t dest_size = std::size(properties[i].extensionName);
DCHECK(dest_size > 0);
properties[i].type = XR_TYPE_EXTENSION_PROPERTIES;
errno_t error = strcpy_s(properties[i].extensionName,
std::size(properties[i].extensionName),
OpenXrTestHelper::kExtensions[i]);
DCHECK(error == 0);
size_t copy_length =
base::strlcpy(properties[i].extensionName,
OpenXrTestHelper::kExtensions[i], dest_size);
DCHECK(copy_length < dest_size);
properties[i].extensionVersion = 1;
}
@ -1020,8 +1022,9 @@ XrResult xrPathToString(XrInstance instance,
RETURN_IF(
buffer_capacity_input <= path_string.size(), XR_ERROR_SIZE_INSUFFICIENT,
"xrPathToString inputsize is not large enough to hold the output string");
errno_t error = strcpy_s(buffer, *buffer_count_output, path_string.data());
DCHECK_EQ(error, 0);
size_t copied_size =
base::strlcpy(buffer, path_string.data(), *buffer_count_output);
DCHECK_LT(copied_size, *buffer_count_output);
return XR_SUCCESS;
}