Commit dd4c907b authored by Kamila Hasanbega's avatar Kamila Hasanbega Committed by Commit Bot

Revert "[WebLayer] Add tests for chrome://weblayer page"

This reverts commit 90c5851b.

Reason for revert: This introduces tests that constantly fail, https://ci.chromium.org/p/chromium/builders/ci/win-asan/8177. 

Original change's description:
> [WebLayer] Add tests for chrome://weblayer page
> 
> This page recently broke (fix in http://crrev.com/c/1880171), so tests
> seem like a good idea.
> 
> This also adds a test helper for executing javascript, and makes the
> NavigateAndWaitForCompletion function work more similarly to the one in
> the instrumentation tests by waiting until the page is finished loading.
> 
> Bug: 1017924
> Change-Id: I8ca048f9a9a92808abf6cfa5d0e091550cc3d9a6
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1880173
> Commit-Queue: Clark DuVall <cduvall@chromium.org>
> Reviewed-by: Scott Violet <sky@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#709552}

TBR=sky@chromium.org,cduvall@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1017924
Change-Id: Ifc5689dc8bb0ec9fdc793bdbb79f44c5388b2266
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1886413Reviewed-by: default avatarKamila Hasanbega <hkamila@chromium.org>
Commit-Queue: Kamila Hasanbega <hkamila@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710272}
parent cfd41acf
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/browser_controls_state.h" #include "content/public/common/browser_controls_state.h"
#include "weblayer/browser/file_select_helper.h" #include "weblayer/browser/file_select_helper.h"
#include "weblayer/browser/isolated_world_ids.h"
#include "weblayer/browser/navigation_controller_impl.h" #include "weblayer/browser/navigation_controller_impl.h"
#include "weblayer/browser/profile_impl.h" #include "weblayer/browser/profile_impl.h"
#include "weblayer/public/browser_observer.h" #include "weblayer/public/browser_observer.h"
...@@ -28,6 +27,7 @@ ...@@ -28,6 +27,7 @@
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "components/embedder_support/android/delegate/color_chooser_android.h" #include "components/embedder_support/android/delegate/color_chooser_android.h"
#include "weblayer/browser/isolated_world_ids.h"
#include "weblayer/browser/java/jni/BrowserControllerImpl_jni.h" #include "weblayer/browser/java/jni/BrowserControllerImpl_jni.h"
#include "weblayer/browser/top_controls_container_view.h" #include "weblayer/browser/top_controls_container_view.h"
#endif #endif
...@@ -47,7 +47,7 @@ struct UserData : public base::SupportsUserData::Data { ...@@ -47,7 +47,7 @@ struct UserData : public base::SupportsUserData::Data {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
BrowserController* g_last_browser_controller; BrowserController* g_last_browser_controller;
void HandleJavaScriptResult( void JavaScriptResultCallback(
const base::android::ScopedJavaGlobalRef<jobject>& callback, const base::android::ScopedJavaGlobalRef<jobject>& callback,
base::Value result) { base::Value result) {
std::string json; std::string json;
...@@ -137,12 +137,6 @@ NavigationController* BrowserControllerImpl::GetNavigationController() { ...@@ -137,12 +137,6 @@ NavigationController* BrowserControllerImpl::GetNavigationController() {
return navigation_controller_.get(); return navigation_controller_.get();
} }
void BrowserControllerImpl::ExecuteScript(const base::string16& script,
JavaScriptResultCallback callback) {
web_contents_->GetMainFrame()->ExecuteJavaScriptInIsolatedWorld(
script, std::move(callback), ISOLATED_WORLD_ID_WEBLAYER);
}
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
void BrowserControllerImpl::AttachToView(views::WebView* web_view) { void BrowserControllerImpl::AttachToView(views::WebView* web_view) {
web_view->SetWebContents(web_contents_.get()); web_view->SetWebContents(web_contents_.get());
...@@ -185,8 +179,10 @@ void BrowserControllerImpl::ExecuteScript( ...@@ -185,8 +179,10 @@ void BrowserControllerImpl::ExecuteScript(
const base::android::JavaParamRef<jstring>& script, const base::android::JavaParamRef<jstring>& script,
const base::android::JavaParamRef<jobject>& callback) { const base::android::JavaParamRef<jobject>& callback) {
base::android::ScopedJavaGlobalRef<jobject> jcallback(env, callback); base::android::ScopedJavaGlobalRef<jobject> jcallback(env, callback);
ExecuteScript(base::android::ConvertJavaStringToUTF16(script), web_contents_->GetMainFrame()->ExecuteJavaScriptInIsolatedWorld(
base::BindOnce(&HandleJavaScriptResult, jcallback)); base::android::ConvertJavaStringToUTF16(script),
base::BindOnce(&JavaScriptResultCallback, jcallback),
ISOLATED_WORLD_ID_WEBLAYER);
} }
#endif #endif
......
...@@ -74,8 +74,6 @@ class BrowserControllerImpl : public BrowserController, ...@@ -74,8 +74,6 @@ class BrowserControllerImpl : public BrowserController,
void AddObserver(BrowserObserver* observer) override; void AddObserver(BrowserObserver* observer) override;
void RemoveObserver(BrowserObserver* observer) override; void RemoveObserver(BrowserObserver* observer) override;
NavigationController* GetNavigationController() override; NavigationController* GetNavigationController() override;
void ExecuteScript(const base::string16& script,
JavaScriptResultCallback callback) override;
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
void AttachToView(views::WebView* web_view) override; void AttachToView(views::WebView* web_view) override;
#endif #endif
......
// Copyright 2019 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 "weblayer/test/weblayer_browser_test.h"
#include "build/build_config.h"
#include "weblayer/test/weblayer_browser_test_utils.h"
namespace weblayer {
using WebLayerWebUIBrowserTest = WebLayerBrowserTest;
IN_PROC_BROWSER_TEST_F(WebLayerWebUIBrowserTest, WebUI) {
NavigateAndWaitForCompletion(GURL("chrome://weblayer"), shell());
base::RunLoop run_loop;
bool result =
ExecuteScript(shell(),
"document.getElementById('remote-debug-label').hidden")
.GetBool();
// The remote debug checkbox should only be visible on Android.
#if defined(OS_ANDROID)
EXPECT_FALSE(result);
#else
EXPECT_TRUE(result);
#endif
}
} // namespace weblayer
...@@ -7,14 +7,8 @@ ...@@ -7,14 +7,8 @@
#include <algorithm> #include <algorithm>
#include "base/callback_forward.h"
#include "base/strings/string16.h"
#include "build/build_config.h" #include "build/build_config.h"
namespace base {
class Value;
}
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
namespace views { namespace views {
class WebView; class WebView;
...@@ -52,10 +46,6 @@ class BrowserController { ...@@ -52,10 +46,6 @@ class BrowserController {
virtual NavigationController* GetNavigationController() = 0; virtual NavigationController* GetNavigationController() = 0;
using JavaScriptResultCallback = base::OnceCallback<void(base::Value)>;
virtual void ExecuteScript(const base::string16& script,
JavaScriptResultCallback callback) = 0;
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
// TODO: this isn't a stable API, so use it now for expediency in the C++ API, // TODO: this isn't a stable API, so use it now for expediency in the C++ API,
// but if we ever want to have backward or forward compatibility in C++ this // but if we ever want to have backward or forward compatibility in C++ this
......
...@@ -84,7 +84,6 @@ test("weblayer_browsertests") { ...@@ -84,7 +84,6 @@ test("weblayer_browsertests") {
] ]
sources = [ sources = [
"../browser/webui/webui_browsertest.cc",
"browsertests_main.cc", "browsertests_main.cc",
"ssl_browsertest.cc", "ssl_browsertest.cc",
"test_launcher_delegate_impl.cc", "test_launcher_delegate_impl.cc",
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include "weblayer/test/weblayer_browser_test_utils.h" #include "weblayer/test/weblayer_browser_test_utils.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "weblayer/public/browser_controller.h" #include "weblayer/public/browser_controller.h"
#include "weblayer/public/navigation.h" #include "weblayer/public/navigation.h"
...@@ -42,10 +40,8 @@ class TestNavigationObserver : public NavigationObserver { ...@@ -42,10 +40,8 @@ class TestNavigationObserver : public NavigationObserver {
// NavigationObserver implementation: // NavigationObserver implementation:
void NavigationCompleted(Navigation* navigation) override { void NavigationCompleted(Navigation* navigation) override {
if (navigation->GetURL() == url_ && if (navigation->GetURL() == url_ &&
event_ == NavigationEventToObserve::Completion) { event_ == NavigationEventToObserve::Completion)
navigation_complete_ = true; std::move(closure_).Run();
CheckComplete();
}
} }
void NavigationFailed(Navigation* navigation) override { void NavigationFailed(Navigation* navigation) override {
...@@ -55,22 +51,10 @@ class TestNavigationObserver : public NavigationObserver { ...@@ -55,22 +51,10 @@ class TestNavigationObserver : public NavigationObserver {
} }
} }
void LoadStateChanged(bool is_loading, bool to_different_document) override {
done_loading_ = !is_loading;
CheckComplete();
}
void CheckComplete() {
if (done_loading_ && navigation_complete_)
std::move(closure_).Run();
}
base::OnceClosure closure_; base::OnceClosure closure_;
const GURL url_; const GURL url_;
NavigationEventToObserve event_; NavigationEventToObserve event_;
BrowserController* browser_; BrowserController* browser_;
bool done_loading_ = false;
bool navigation_complete_ = false;
}; };
// Navigates to |url| in |shell| and waits for |event| to occur. // Navigates to |url| in |shell| and waits for |event| to occur.
...@@ -98,18 +82,4 @@ void NavigateAndWaitForFailure(const GURL& url, Shell* shell) { ...@@ -98,18 +82,4 @@ void NavigateAndWaitForFailure(const GURL& url, Shell* shell) {
url, shell, TestNavigationObserver::NavigationEventToObserve::Failure); url, shell, TestNavigationObserver::NavigationEventToObserve::Failure);
} }
base::Value ExecuteScript(Shell* shell, const std::string& script) {
base::Value final_result;
base::RunLoop run_loop;
shell->browser_controller()->ExecuteScript(
base::ASCIIToUTF16(script),
base::BindLambdaForTesting(
[&run_loop, &final_result](base::Value result) {
final_result = std::move(result);
run_loop.Quit();
}));
run_loop.Run();
return final_result;
}
} // namespace weblayer } // namespace weblayer
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#ifndef WEBLAYER_TEST_WEBLAYER_BROWSER_TEST_UTILS_H_ #ifndef WEBLAYER_TEST_WEBLAYER_BROWSER_TEST_UTILS_H_
#define WEBLAYER_TEST_WEBLAYER_BROWSER_TEST_UTILS_H_ #define WEBLAYER_TEST_WEBLAYER_BROWSER_TEST_UTILS_H_
#include "base/values.h"
class GURL; class GURL;
namespace weblayer { namespace weblayer {
...@@ -18,9 +16,6 @@ void NavigateAndWaitForCompletion(const GURL& url, Shell* shell); ...@@ -18,9 +16,6 @@ void NavigateAndWaitForCompletion(const GURL& url, Shell* shell);
// Navigates |shell| to |url| and wait for failed navigation. // Navigates |shell| to |url| and wait for failed navigation.
void NavigateAndWaitForFailure(const GURL& url, Shell* shell); void NavigateAndWaitForFailure(const GURL& url, Shell* shell);
// Executes |script| in |shell| and returns the result.
base::Value ExecuteScript(Shell* shell, const std::string& script);
} // namespace weblayer } // namespace weblayer
#endif // WEBLAYER_TEST_WEBLAYER_BROWSER_TEST_UTILS_H_ #endif // WEBLAYER_TEST_WEBLAYER_BROWSER_TEST_UTILS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment