This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "base/values.h"
#include "chrome/browser/extensions/api/web_navigation/frame_navigation_state.h"
#include "chrome/test/base/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
content::RenderViewHost* fake_rvh =
reinterpret_cast<content::RenderViewHost*>(31337);
TEST(FrameNavigationStateTest, TrackFrame) {
FrameNavigationState navigation_state;
const FrameNavigationState::FrameID frame_id0(-1, fake_rvh);
const FrameNavigationState::FrameID frame_id1(23, fake_rvh);
const FrameNavigationState::FrameID frame_id2(42, fake_rvh);
const GURL url1("http://www.google.com/");
const GURL url2("http://mail.google.com/");
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1));
EXPECT_FALSE(navigation_state.IsValidFrame(frame_id1));
navigation_state.TrackFrame(frame_id1, frame_id0, url1, true, false, false);
navigation_state.SetNavigationCommitted(frame_id1);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1));
EXPECT_TRUE(navigation_state.IsValidFrame(frame_id1));
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2));
EXPECT_FALSE(navigation_state.IsValidFrame(frame_id2));
navigation_state.TrackFrame(frame_id2, frame_id1, url2, false, false, false);
navigation_state.SetNavigationCommitted(frame_id2);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2));
EXPECT_TRUE(navigation_state.IsValidFrame(frame_id2));
EXPECT_TRUE(navigation_state.IsMainFrame(frame_id1));
EXPECT_EQ(url1, navigation_state.GetUrl(frame_id1));
EXPECT_FALSE(navigation_state.IsMainFrame(frame_id2));
EXPECT_EQ(url2, navigation_state.GetUrl(frame_id2));
EXPECT_EQ(frame_id1, navigation_state.GetMainFrameID());
navigation_state.StopTrackingFramesInRVH(fake_rvh,
FrameNavigationState::FrameID());
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1));
EXPECT_FALSE(navigation_state.IsValidFrame(frame_id1));
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2));
EXPECT_FALSE(navigation_state.IsValidFrame(frame_id2));
}
TEST(FrameNavigationStateTest, ErrorState) {
FrameNavigationState navigation_state;
const FrameNavigationState::FrameID frame_id0(-1, fake_rvh);
const FrameNavigationState::FrameID frame_id1(42, fake_rvh);
const GURL url("http://www.google.com/");
navigation_state.TrackFrame(frame_id1, frame_id0, url, true, false, false);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1));
EXPECT_FALSE(navigation_state.GetErrorOccurredInFrame(frame_id1));
navigation_state.SetErrorOccurredInFrame(frame_id1);
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1));
EXPECT_TRUE(navigation_state.GetErrorOccurredInFrame(frame_id1));
navigation_state.TrackFrame(frame_id1, frame_id0, GURL(), true, true, false);
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1));
EXPECT_TRUE(navigation_state.GetErrorOccurredInFrame(frame_id1));
navigation_state.TrackFrame(frame_id1, frame_id0, url, true, false, false);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1));
EXPECT_FALSE(navigation_state.GetErrorOccurredInFrame(frame_id1));
}
TEST(FrameNavigationStateTest, ErrorStateFrame) {
FrameNavigationState navigation_state;
const FrameNavigationState::FrameID frame_id0(-1, fake_rvh);
const FrameNavigationState::FrameID frame_id1(23, fake_rvh);
const FrameNavigationState::FrameID frame_id2(42, fake_rvh);
const GURL url("http://www.google.com/");
navigation_state.TrackFrame(frame_id1, frame_id0, url, true, false, false);
navigation_state.TrackFrame(frame_id2, frame_id1, url, false, false, false);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1));
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2));
navigation_state.SetErrorOccurredInFrame(frame_id2);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1));
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2));
navigation_state.TrackFrame(frame_id2, frame_id1, GURL(), false, true, false);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1));
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2));
navigation_state.TrackFrame(frame_id2, frame_id1, url, false, false, false);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1));
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2));
}
TEST(FrameNavigationStateTest, WebSafeScheme) {
FrameNavigationState navigation_state;
const FrameNavigationState::FrameID frame_id0(-1, fake_rvh);
const FrameNavigationState::FrameID frame_id1(23, fake_rvh);
const GURL url("unsafe://www.google.com/");
navigation_state.TrackFrame(frame_id1, frame_id0, url, true, false, false);
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1));
}
TEST(FrameNavigationStateTest, ParentFrameID) {
FrameNavigationState navigation_state;
const FrameNavigationState::FrameID frame_id0(-1, fake_rvh);
const FrameNavigationState::FrameID frame_id1(23, fake_rvh);
const FrameNavigationState::FrameID frame_id2(42, fake_rvh);
const GURL url("http://www.google.com/");
navigation_state.TrackFrame(frame_id1, frame_id0, url, true, false, false);
navigation_state.TrackFrame(frame_id2, frame_id1, url, false, false, false);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1));
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2));
EXPECT_TRUE(navigation_state.GetParentFrameID(frame_id1) == frame_id0);
EXPECT_TRUE(navigation_state.GetParentFrameID(frame_id2) == frame_id1);
}
TEST(FrameNavigationStateTest, SrcDoc) {
FrameNavigationState navigation_state;
const FrameNavigationState::FrameID frame_id0(-1, fake_rvh);
const FrameNavigationState::FrameID frame_id1(23, fake_rvh);
const FrameNavigationState::FrameID frame_id2(42, fake_rvh);
const GURL url("http://www.google.com/");
const GURL blank("about:blank");
const GURL srcdoc("about:srcdoc");
navigation_state.TrackFrame(frame_id1, frame_id0, url, true, false, false);
navigation_state.TrackFrame(frame_id2, frame_id1, blank, false, false, true);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1));
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2));
EXPECT_TRUE(navigation_state.GetUrl(frame_id1) == url);
EXPECT_TRUE(navigation_state.GetUrl(frame_id2) == srcdoc);
EXPECT_TRUE(navigation_state.IsValidUrl(srcdoc));
}
TEST(FrameNavigationStateTest, DetachFrame) {
FrameNavigationState navigation_state;
const FrameNavigationState::FrameID frame_id0(-1, fake_rvh);
const FrameNavigationState::FrameID frame_id1(23, fake_rvh);
const FrameNavigationState::FrameID frame_id2(42, fake_rvh);
const GURL url1("http://www.google.com/");
const GURL url2("http://mail.google.com/");
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1));
EXPECT_FALSE(navigation_state.IsValidFrame(frame_id1));
navigation_state.TrackFrame(frame_id1, frame_id0, url1, true, false, false);
navigation_state.SetNavigationCommitted(frame_id1);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1));
EXPECT_TRUE(navigation_state.IsValidFrame(frame_id1));
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2));
EXPECT_FALSE(navigation_state.IsValidFrame(frame_id2));
navigation_state.TrackFrame(frame_id2, frame_id1, url2, false, false, false);
navigation_state.SetNavigationCommitted(frame_id2);
EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2));
EXPECT_TRUE(navigation_state.IsValidFrame(frame_id2));
EXPECT_TRUE(navigation_state.IsMainFrame(frame_id1));
EXPECT_EQ(url1, navigation_state.GetUrl(frame_id1));
EXPECT_FALSE(navigation_state.IsMainFrame(frame_id2));
EXPECT_EQ(url2, navigation_state.GetUrl(frame_id2));
EXPECT_EQ(frame_id1, navigation_state.GetMainFrameID());
navigation_state.FrameDetached(frame_id2);
EXPECT_TRUE(navigation_state.IsMainFrame(frame_id1));
EXPECT_EQ(url1, navigation_state.GetUrl(frame_id1));
EXPECT_EQ(frame_id1, navigation_state.GetMainFrameID());
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2));
EXPECT_FALSE(navigation_state.IsValidFrame(frame_id2));
}
}