Commit 489df11c authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

[fuchsia] Implement Frame::GetVisibleEntry() API method.

This method uses the NavigationController API to query the committed
navigational state on a Frame.

Bug: 852145
Change-Id: I49f9122753c393ef33d67905353b5ba1afad157a
Reviewed-on: https://chromium-review.googlesource.com/1182507Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585237}
parent 037dd704
...@@ -233,5 +233,103 @@ IN_PROC_BROWSER_TEST_F(ContextImplTest, ReloadFrame) { ...@@ -233,5 +233,103 @@ IN_PROC_BROWSER_TEST_F(ContextImplTest, ReloadFrame) {
} }
} }
IN_PROC_BROWSER_TEST_F(ContextImplTest, GetVisibleEntry) {
chromium::web::FramePtr frame = CreateFrame();
chromium::web::NavigationControllerPtr controller;
frame->GetNavigationController(controller.NewRequest());
// Verify that a Frame returns a null NavigationEntry prior to receiving any
// LoadUrl() calls.
{
base::RunLoop run_loop;
controller->GetVisibleEntry(
[&run_loop](std::unique_ptr<chromium::web::NavigationEntry> details) {
EXPECT_EQ(nullptr, details.get());
run_loop.Quit();
});
run_loop.Run();
}
ASSERT_TRUE(embedded_test_server()->Start());
GURL title1(embedded_test_server()->GetURL(kPage1Path));
GURL title2(embedded_test_server()->GetURL(kPage2Path));
// Navigate to a page.
{
base::RunLoop run_loop;
EXPECT_CALL(*this, OnNavigationStateChanged(testing::AllOf(
Field(&NavigationDetails::title, kPage1Title),
Field(&NavigationDetails::url, IsSet()))))
.WillOnce(testing::InvokeWithoutArgs([&run_loop] { run_loop.Quit(); }));
controller->LoadUrl(title1.spec(), nullptr);
run_loop.Run();
}
// Verify that GetVisibleEntry() reflects the new Frame navigation state.
{
base::RunLoop run_loop;
controller->GetVisibleEntry(
[&run_loop,
&title1](std::unique_ptr<chromium::web::NavigationEntry> details) {
EXPECT_TRUE(details);
EXPECT_EQ(details->url, title1.spec());
EXPECT_EQ(details->title, kPage1Title);
run_loop.Quit();
});
run_loop.Run();
}
// Navigate to another page.
{
base::RunLoop run_loop;
EXPECT_CALL(*this, OnNavigationStateChanged(testing::AllOf(
Field(&NavigationDetails::title, kPage2Title),
Field(&NavigationDetails::url, IsSet()))))
.WillOnce(testing::InvokeWithoutArgs([&run_loop] { run_loop.Quit(); }));
controller->LoadUrl(title2.spec(), nullptr);
run_loop.Run();
}
// Verify the navigation with GetVisibleEntry().
{
base::RunLoop run_loop;
controller->GetVisibleEntry(
[&run_loop,
&title2](std::unique_ptr<chromium::web::NavigationEntry> details) {
EXPECT_TRUE(details);
EXPECT_EQ(details->url, title2.spec());
EXPECT_EQ(details->title, kPage2Title);
run_loop.Quit();
});
run_loop.Run();
}
// Navigate back to the first page.
{
base::RunLoop run_loop;
EXPECT_CALL(*this, OnNavigationStateChanged(testing::AllOf(
Field(&NavigationDetails::title, kPage1Title),
Field(&NavigationDetails::url, IsSet()))))
.WillOnce(testing::InvokeWithoutArgs([&run_loop] { run_loop.Quit(); }));
controller->GoBack();
run_loop.Run();
}
// Verify the navigation with GetVisibleEntry().
{
base::RunLoop run_loop;
controller->GetVisibleEntry(
[&run_loop,
&title1](std::unique_ptr<chromium::web::NavigationEntry> details) {
EXPECT_TRUE(details);
EXPECT_EQ(details->url, title1.spec());
EXPECT_EQ(details->title, kPage1Title);
run_loop.Quit();
});
run_loop.Run();
}
}
} // namespace } // namespace
} // namespace webrunner } // namespace webrunner
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ui/aura/layout_manager.h" #include "ui/aura/layout_manager.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -60,6 +60,15 @@ class LayoutManagerImpl : public aura::LayoutManager { ...@@ -60,6 +60,15 @@ class LayoutManagerImpl : public aura::LayoutManager {
DISALLOW_COPY_AND_ASSIGN(LayoutManagerImpl); DISALLOW_COPY_AND_ASSIGN(LayoutManagerImpl);
}; };
chromium::web::NavigationEntry ConvertContentNavigationEntry(
content::NavigationEntry* entry) {
DCHECK(entry);
chromium::web::NavigationEntry converted;
converted.title = base::UTF16ToUTF8(entry->GetTitle());
converted.url = entry->GetURL().spec();
return converted;
}
} // namespace } // namespace
FrameImpl::FrameImpl(std::unique_ptr<content::WebContents> web_contents, FrameImpl::FrameImpl(std::unique_ptr<content::WebContents> web_contents,
...@@ -146,8 +155,15 @@ void FrameImpl::Reload(chromium::web::ReloadType type) { ...@@ -146,8 +155,15 @@ void FrameImpl::Reload(chromium::web::ReloadType type) {
} }
void FrameImpl::GetVisibleEntry(GetVisibleEntryCallback callback) { void FrameImpl::GetVisibleEntry(GetVisibleEntryCallback callback) {
NOTIMPLEMENTED(); content::NavigationEntry* entry =
callback(nullptr); web_contents_->GetController().GetVisibleEntry();
if (!entry) {
callback(nullptr);
return;
}
chromium::web::NavigationEntry output = ConvertContentNavigationEntry(entry);
callback(std::make_unique<chromium::web::NavigationEntry>(std::move(output)));
} }
void FrameImpl::DidFinishLoad(content::RenderFrameHost* render_frame_host, void FrameImpl::DidFinishLoad(content::RenderFrameHost* render_frame_host,
......
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