Commit 3baf392a authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove use of NOTIFICATION_TAB_ADDED from WebNavigationApiTest

Bug: 268984
Change-Id: If26a8d4449f427216bc6472ed17f392f54c73c73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1704869Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678335}
parent 977bcc6b
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_browser_main.h" #include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/download/download_browsertest.h" #include "chrome/browser/download/download_browsertest.h"
#include "chrome/browser/download/download_prefs.h" #include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
...@@ -67,39 +66,36 @@ namespace { ...@@ -67,39 +66,36 @@ namespace {
// |script| in the last committed RVH and resumes the load when a URL ending in // |script| in the last committed RVH and resumes the load when a URL ending in
// |until_url_suffix| commits. This class expects |script| to trigger the load // |until_url_suffix| commits. This class expects |script| to trigger the load
// of an URL ending in |until_url_suffix|. // of an URL ending in |until_url_suffix|.
class DelayLoadStartAndExecuteJavascript class DelayLoadStartAndExecuteJavascript : public TabStripModelObserver,
: public content::NotificationObserver, public content::WebContentsObserver {
public content::WebContentsObserver {
public: public:
DelayLoadStartAndExecuteJavascript( DelayLoadStartAndExecuteJavascript(Browser* browser,
const GURL& delay_url, const GURL& delay_url,
const std::string& script, const std::string& script,
const std::string& until_url_suffix) const std::string& until_url_suffix)
: content::WebContentsObserver(), : content::WebContentsObserver(),
delay_url_(delay_url), delay_url_(delay_url),
until_url_suffix_(until_url_suffix), until_url_suffix_(until_url_suffix),
script_(script), script_(script) {
has_user_gesture_(false), tab_strip_observer_.Add(browser->tab_strip_model());
script_was_executed_(false),
rfh_(nullptr) {
registrar_.Add(this,
chrome::NOTIFICATION_TAB_ADDED,
content::NotificationService::AllSources());
} }
~DelayLoadStartAndExecuteJavascript() override {} ~DelayLoadStartAndExecuteJavascript() override {}
void Observe(int type, // TabStripModelObserver:
const content::NotificationSource& source, void OnTabStripModelChanged(
const content::NotificationDetails& details) override { TabStripModel* tab_strip_model,
if (type != chrome::NOTIFICATION_TAB_ADDED) { const TabStripModelChange& change,
NOTREACHED(); const TabStripSelectionChange& selection) override {
if (change.type() != TabStripModelChange::kInserted)
return; return;
}
content::WebContentsObserver::Observe( content::WebContentsObserver::Observe(
content::Details<content::WebContents>(details).ptr()); change.GetInsert()->contents[0].contents);
registrar_.RemoveAll(); tab_strip_observer_.RemoveAll();
} }
// WebContentsObserver:
void DidStartNavigation( void DidStartNavigation(
content::NavigationHandle* navigation_handle) override { content::NavigationHandle* navigation_handle) override {
if (navigation_handle->GetURL() != delay_url_ || !rfh_) if (navigation_handle->GetURL() != delay_url_ || !rfh_)
...@@ -128,7 +124,7 @@ class DelayLoadStartAndExecuteJavascript ...@@ -128,7 +124,7 @@ class DelayLoadStartAndExecuteJavascript
if (script_was_executed_ && if (script_was_executed_ &&
base::EndsWith(navigation_handle->GetURL().spec(), until_url_suffix_, base::EndsWith(navigation_handle->GetURL().spec(), until_url_suffix_,
base::CompareCase::SENSITIVE)) { base::CompareCase::SENSITIVE)) {
content::WebContentsObserver::Observe(NULL); content::WebContentsObserver::Observe(nullptr);
if (throttle_) if (throttle_)
throttle_->Unblock(); throttle_->Unblock();
} }
...@@ -168,16 +164,16 @@ class DelayLoadStartAndExecuteJavascript ...@@ -168,16 +164,16 @@ class DelayLoadStartAndExecuteJavascript
bool throttled_ = false; bool throttled_ = false;
}; };
content::NotificationRegistrar registrar_;
base::WeakPtr<WillStartRequestObserverThrottle> throttle_; base::WeakPtr<WillStartRequestObserverThrottle> throttle_;
ScopedObserver<TabStripModel, TabStripModelObserver> tab_strip_observer_{
this};
GURL delay_url_; GURL delay_url_;
std::string until_url_suffix_; std::string until_url_suffix_;
std::string script_; std::string script_;
bool has_user_gesture_; bool has_user_gesture_ = false;
bool script_was_executed_; bool script_was_executed_ = false;
content::RenderFrameHost* rfh_; content::RenderFrameHost* rfh_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(DelayLoadStartAndExecuteJavascript); DISALLOW_COPY_AND_ASSIGN(DelayLoadStartAndExecuteJavascript);
}; };
...@@ -499,13 +495,11 @@ IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, CrossProcess) { ...@@ -499,13 +495,11 @@ IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, CrossProcess) {
// See crossProcess/d.html. // See crossProcess/d.html.
DelayLoadStartAndExecuteJavascript call_script( DelayLoadStartAndExecuteJavascript call_script(
embedded_test_server()->GetURL("/test1"), browser(), embedded_test_server()->GetURL("/test1"), "navigate2()",
"navigate2()",
"empty.html"); "empty.html");
DelayLoadStartAndExecuteJavascript call_script_user_gesture( DelayLoadStartAndExecuteJavascript call_script_user_gesture(
embedded_test_server()->GetURL("/test2"), browser(), embedded_test_server()->GetURL("/test2"), "navigate2()",
"navigate2()",
"empty.html"); "empty.html");
call_script_user_gesture.set_has_user_gesture(true); call_script_user_gesture.set_has_user_gesture(true);
...@@ -518,14 +512,12 @@ IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, DISABLED_CrossProcessFragment) { ...@@ -518,14 +512,12 @@ IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, DISABLED_CrossProcessFragment) {
// See crossProcessFragment/f.html. // See crossProcessFragment/f.html.
DelayLoadStartAndExecuteJavascript call_script3( DelayLoadStartAndExecuteJavascript call_script3(
embedded_test_server()->GetURL("/test3"), browser(), embedded_test_server()->GetURL("/test3"), "updateFragment()",
"updateFragment()",
base::StringPrintf("f.html?%u#foo", embedded_test_server()->port())); base::StringPrintf("f.html?%u#foo", embedded_test_server()->port()));
// See crossProcessFragment/g.html. // See crossProcessFragment/g.html.
DelayLoadStartAndExecuteJavascript call_script4( DelayLoadStartAndExecuteJavascript call_script4(
embedded_test_server()->GetURL("/test4"), browser(), embedded_test_server()->GetURL("/test4"), "updateFragment()",
"updateFragment()",
base::StringPrintf("g.html?%u#foo", embedded_test_server()->port())); base::StringPrintf("g.html?%u#foo", embedded_test_server()->port()));
ASSERT_TRUE(RunExtensionTest("webnavigation/crossProcessFragment")) ASSERT_TRUE(RunExtensionTest("webnavigation/crossProcessFragment"))
...@@ -537,20 +529,17 @@ IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, CrossProcessHistory) { ...@@ -537,20 +529,17 @@ IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, CrossProcessHistory) {
// See crossProcessHistory/e.html. // See crossProcessHistory/e.html.
DelayLoadStartAndExecuteJavascript call_script2( DelayLoadStartAndExecuteJavascript call_script2(
embedded_test_server()->GetURL("/test2"), browser(), embedded_test_server()->GetURL("/test2"), "updateHistory()",
"updateHistory()",
"empty.html"); "empty.html");
// See crossProcessHistory/h.html. // See crossProcessHistory/h.html.
DelayLoadStartAndExecuteJavascript call_script5( DelayLoadStartAndExecuteJavascript call_script5(
embedded_test_server()->GetURL("/test5"), browser(), embedded_test_server()->GetURL("/test5"), "updateHistory()",
"updateHistory()",
"empty.html"); "empty.html");
// See crossProcessHistory/i.html. // See crossProcessHistory/i.html.
DelayLoadStartAndExecuteJavascript call_script6( DelayLoadStartAndExecuteJavascript call_script6(
embedded_test_server()->GetURL("/test6"), browser(), embedded_test_server()->GetURL("/test6"), "updateHistory()",
"updateHistory()",
"empty.html"); "empty.html");
ASSERT_TRUE(RunExtensionTest("webnavigation/crossProcessHistory")) ASSERT_TRUE(RunExtensionTest("webnavigation/crossProcessHistory"))
......
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