Commit bc1b2476 authored by Yiming Zhou's avatar Yiming Zhou Committed by Commit Bot

Add two more hooks to detect target frames.

Each action in the Captured Sites Automation Framework has a target
frame. The framework uses the IFrameWaiter object to acquire a handle to the RenderFrameHost of
the target frame. A target iframe can be identified by its name, its URL
or the origin of its URL.

Currently the IFrameWaiter object scans for potential targets everytime
Chrome adds a new frame. This change adds 2 additional hooks to
IFrameWaiter to scan for potential targets:

1. When a frame changes its name.
2. When a frame finishes loading a new URL.

Bug: 847905
Change-Id: Ie2b8c2f19a9f08696d474aff6af019ae116b513c
Reviewed-on: https://chromium-review.googlesource.com/c/1260510
Commit-Queue: Yiming Zhou <uwyiming@google.com>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596888}
parent d0505580
...@@ -197,6 +197,38 @@ void IFrameWaiter::RenderFrameCreated( ...@@ -197,6 +197,38 @@ void IFrameWaiter::RenderFrameCreated(
} }
} }
void IFrameWaiter::DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) {
if (!run_loop_.running())
return;
switch (query_type_) {
case ORIGIN:
if (validated_url.GetOrigin() == origin_)
run_loop_.Quit();
break;
case URL:
if (FrameHasSourceUrl(validated_url, render_frame_host))
run_loop_.Quit();
break;
default:
break;
}
}
void IFrameWaiter::FrameNameChanged(content::RenderFrameHost* render_frame_host,
const std::string& name) {
if (!run_loop_.running())
return;
switch (query_type_) {
case NAME:
if (FrameMatchesName(name, render_frame_host))
run_loop_.Quit();
break;
default:
break;
}
}
bool IFrameWaiter::FrameHasOrigin(const GURL& origin, bool IFrameWaiter::FrameHasOrigin(const GURL& origin,
content::RenderFrameHost* frame) { content::RenderFrameHost* frame) {
GURL url = frame->GetLastCommittedURL(); GURL url = frame->GetLastCommittedURL();
...@@ -229,7 +261,7 @@ void TestRecipeReplayer::SetUpCommandLine(base::CommandLine* command_line) { ...@@ -229,7 +261,7 @@ void TestRecipeReplayer::SetUpCommandLine(base::CommandLine* command_line) {
"MAP *:443 127.0.0.1:%d," "MAP *:443 127.0.0.1:%d,"
// Uncomment to use the live autofill prediction server. // Uncomment to use the live autofill prediction server.
//"EXCLUDE clients1.google.com," // "EXCLUDE clients1.google.com,"
"EXCLUDE localhost", "EXCLUDE localhost",
kHostHttpPort, kHostHttpsPort)); kHostHttpPort, kHostHttpsPort));
} }
......
...@@ -9,11 +9,14 @@ ...@@ -9,11 +9,14 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "services/network/public/cpp/network_switches.h" #include "services/network/public/cpp/network_switches.h"
namespace content {
class RenderFrameHost;
class WebContents;
} // namespace content
namespace captured_sites_test_utils { namespace captured_sites_test_utils {
// The amount of time to wait for an action to complete, or for a page element // The amount of time to wait for an action to complete, or for a page element
...@@ -118,6 +121,10 @@ class IFrameWaiter : public content::WebContentsObserver { ...@@ -118,6 +121,10 @@ class IFrameWaiter : public content::WebContentsObserver {
// content::WebContentsObserver // content::WebContentsObserver
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override; void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
void DidFinishLoad(content::RenderFrameHost* render_frame_host,
const GURL& validated_url) override;
void FrameNameChanged(content::RenderFrameHost* render_frame_host,
const std::string& name) override;
QueryType query_type_; QueryType query_type_;
base::RunLoop run_loop_; base::RunLoop run_loop_;
......
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