| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Tests common functionality used by the Chrome Extensions webNavigation API | |
| 6 // implementation. | |
| 7 | |
| 8 #include "base/values.h" | |
| 9 #include "chrome/browser/extensions/extension_webnavigation_api.h" | |
| 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 11 #include "chrome/test/base/testing_profile.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 | |
| 15 class FrameNavigationStateTest : public ChromeRenderViewHostTestHarness { | |
| 16 }; | |
| 17 | |
| 18 // Test that a frame is correctly tracked, and removed once the tab contents | |
| 19 // goes away. | |
| 20 TEST_F(FrameNavigationStateTest, TrackFrame) { | |
| 21 FrameNavigationState navigation_state; | |
| 22 const int64 frame_id1 = 23; | |
| 23 const int64 frame_id2 = 42; | |
| 24 const GURL url1("http://www.google.com/"); | |
| 25 const GURL url2("http://mail.google.com/"); | |
| 26 | |
| 27 // Create a main frame. | |
| 28 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1)); | |
| 29 EXPECT_FALSE(navigation_state.IsValidFrame(frame_id1)); | |
| 30 navigation_state.TrackFrame(frame_id1, url1, true, false); | |
| 31 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); | |
| 32 EXPECT_TRUE(navigation_state.IsValidFrame(frame_id1)); | |
| 33 | |
| 34 // Add a sub frame. | |
| 35 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); | |
| 36 EXPECT_FALSE(navigation_state.IsValidFrame(frame_id2)); | |
| 37 navigation_state.TrackFrame(frame_id2, url2, false, false); | |
| 38 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2)); | |
| 39 EXPECT_TRUE(navigation_state.IsValidFrame(frame_id2)); | |
| 40 | |
| 41 // Check frame state. | |
| 42 EXPECT_TRUE(navigation_state.IsMainFrame(frame_id1)); | |
| 43 EXPECT_EQ(url1, navigation_state.GetUrl(frame_id1)); | |
| 44 EXPECT_FALSE(navigation_state.IsMainFrame(frame_id2)); | |
| 45 EXPECT_EQ(url2, navigation_state.GetUrl(frame_id2)); | |
| 46 EXPECT_EQ(frame_id1, navigation_state.GetMainFrameID()); | |
| 47 } | |
| 48 | |
| 49 // Test that no events can be sent for a frame after an error occurred, but | |
| 50 // before a new navigation happened in this frame. | |
| 51 TEST_F(FrameNavigationStateTest, ErrorState) { | |
| 52 FrameNavigationState navigation_state; | |
| 53 const int64 frame_id = 42; | |
| 54 const GURL url("http://www.google.com/"); | |
| 55 | |
| 56 navigation_state.TrackFrame(frame_id, url, true, false); | |
| 57 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); | |
| 58 EXPECT_FALSE(navigation_state.GetErrorOccurredInFrame(frame_id)); | |
| 59 | |
| 60 // After an error occurred, no further events should be sent. | |
| 61 navigation_state.SetErrorOccurredInFrame(frame_id); | |
| 62 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); | |
| 63 EXPECT_TRUE(navigation_state.GetErrorOccurredInFrame(frame_id)); | |
| 64 | |
| 65 // Navigations to a network error page should be ignored. | |
| 66 navigation_state.TrackFrame(frame_id, GURL(), true, true); | |
| 67 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); | |
| 68 EXPECT_TRUE(navigation_state.GetErrorOccurredInFrame(frame_id)); | |
| 69 | |
| 70 // However, when the frame navigates again, it should send events again. | |
| 71 navigation_state.TrackFrame(frame_id, url, true, false); | |
| 72 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); | |
| 73 EXPECT_FALSE(navigation_state.GetErrorOccurredInFrame(frame_id)); | |
| 74 } | |
| 75 | |
| 76 // Tests that for a sub frame, no events are send after an error occurred, but | |
| 77 // before a new navigation happened in this frame. | |
| 78 TEST_F(FrameNavigationStateTest, ErrorStateFrame) { | |
| 79 FrameNavigationState navigation_state; | |
| 80 const int64 frame_id1 = 23; | |
| 81 const int64 frame_id2 = 42; | |
| 82 const GURL url("http://www.google.com/"); | |
| 83 | |
| 84 navigation_state.TrackFrame(frame_id1, url, true, false); | |
| 85 navigation_state.TrackFrame(frame_id2, url, false, false); | |
| 86 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); | |
| 87 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2)); | |
| 88 | |
| 89 // After an error occurred, no further events should be sent. | |
| 90 navigation_state.SetErrorOccurredInFrame(frame_id2); | |
| 91 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); | |
| 92 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); | |
| 93 | |
| 94 // Navigations to a network error page should be ignored. | |
| 95 navigation_state.TrackFrame(frame_id2, GURL(), false, true); | |
| 96 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); | |
| 97 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); | |
| 98 | |
| 99 // However, when the frame navigates again, it should send events again. | |
| 100 navigation_state.TrackFrame(frame_id2, url, false, false); | |
| 101 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); | |
| 102 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2)); | |
| 103 } | |
| 104 | |
| 105 // Tests that no events are send for a not web-safe scheme. | |
| 106 TEST_F(FrameNavigationStateTest, WebSafeScheme) { | |
| 107 FrameNavigationState navigation_state; | |
| 108 const int64 frame_id = 23; | |
| 109 const GURL url("unsafe://www.google.com/"); | |
| 110 | |
| 111 navigation_state.TrackFrame(frame_id, url, true, false); | |
| 112 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); | |
| 113 } | |
| OLD | NEW |