| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Tests common functionality used by the Chrome Extensions webNavigation API | 5 // Tests common functionality used by the Chrome Extensions webNavigation API |
| 6 // implementation. | 6 // implementation. |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/browser_thread.h" | 11 #include "chrome/browser/browser_thread.h" |
| 12 #include "chrome/browser/extensions/extension_webnavigation_api.h" | 12 #include "chrome/browser/extensions/extension_webnavigation_api.h" |
| 13 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 13 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
| 14 #include "chrome/browser/tab_contents/test_tab_contents.h" | 14 #include "chrome/browser/tab_contents/test_tab_contents.h" |
| 15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 16 #include "chrome/test/testing_profile.h" | 16 #include "chrome/test/testing_profile.h" |
| 17 | 17 |
| 18 |
| 18 class FrameNavigationStateTest : public RenderViewHostTestHarness { | 19 class FrameNavigationStateTest : public RenderViewHostTestHarness { |
| 19 }; | 20 }; |
| 20 | 21 |
| 21 // Test that a frame is correctly tracked, and removed once the tab contents | 22 // Test that a frame is correctly tracked, and removed once the tab contents |
| 22 // goes away. | 23 // goes away. |
| 23 TEST_F(FrameNavigationStateTest, TrackFrame) { | 24 TEST_F(FrameNavigationStateTest, TrackFrame) { |
| 24 FrameNavigationState navigation_state; | 25 FrameNavigationState navigation_state; |
| 25 const long long frame_id1 = 23; | 26 const int64 frame_id1 = 23; |
| 26 const long long frame_id2 = 42; | 27 const int64 frame_id2 = 42; |
| 27 const GURL url1("http://www.google.com/"); | 28 const GURL url1("http://www.google.com/"); |
| 28 const GURL url2("http://mail.google.com/"); | 29 const GURL url2("http://mail.google.com/"); |
| 29 | 30 |
| 30 // Create a main frame. | 31 // Create a main frame. |
| 31 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1)); | 32 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1)); |
| 32 navigation_state.TrackFrame(frame_id1, url1, true, contents()); | 33 navigation_state.TrackFrame(frame_id1, url1, true, contents()); |
| 33 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); | 34 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); |
| 34 | 35 |
| 35 // Add a sub frame. | 36 // Add a sub frame. |
| 36 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); | 37 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 47 // Removing the tab contents should also remove all state of its frames. | 48 // Removing the tab contents should also remove all state of its frames. |
| 48 navigation_state.RemoveTabContentsState(contents()); | 49 navigation_state.RemoveTabContentsState(contents()); |
| 49 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1)); | 50 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1)); |
| 50 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); | 51 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Test that no events can be sent for a frame after an error occurred, but | 54 // Test that no events can be sent for a frame after an error occurred, but |
| 54 // before a new navigation happened in this frame. | 55 // before a new navigation happened in this frame. |
| 55 TEST_F(FrameNavigationStateTest, ErrorState) { | 56 TEST_F(FrameNavigationStateTest, ErrorState) { |
| 56 FrameNavigationState navigation_state; | 57 FrameNavigationState navigation_state; |
| 57 const long long frame_id = 42; | 58 const int64 frame_id = 42; |
| 58 const GURL url("http://www.google.com/"); | 59 const GURL url("http://www.google.com/"); |
| 59 | 60 |
| 60 navigation_state.TrackFrame(frame_id, url, true, contents()); | 61 navigation_state.TrackFrame(frame_id, url, true, contents()); |
| 61 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); | 62 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); |
| 62 | 63 |
| 63 // After an error occurred, no further events should be sent. | 64 // After an error occurred, no further events should be sent. |
| 64 navigation_state.ErrorOccurredInFrame(frame_id); | 65 navigation_state.ErrorOccurredInFrame(frame_id); |
| 65 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); | 66 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); |
| 66 | 67 |
| 67 // Navigations to the "unreachable web data" URL should be ignored. | 68 // Navigations to the "unreachable web data" URL should be ignored. |
| 68 navigation_state.TrackFrame( | 69 navigation_state.TrackFrame( |
| 69 frame_id, GURL(chrome::kUnreachableWebDataURL), true, contents()); | 70 frame_id, GURL(chrome::kUnreachableWebDataURL), true, contents()); |
| 70 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); | 71 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); |
| 71 | 72 |
| 72 // However, when the frame navigates again, it should send events again. | 73 // However, when the frame navigates again, it should send events again. |
| 73 navigation_state.TrackFrame(frame_id, url, true, contents()); | 74 navigation_state.TrackFrame(frame_id, url, true, contents()); |
| 74 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); | 75 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); |
| 75 } | 76 } |
| 76 | 77 |
| 77 // Tests that for a sub frame, no events are send after an error occurred, but | 78 // Tests that for a sub frame, no events are send after an error occurred, but |
| 78 // before a new navigation happened in this frame. | 79 // before a new navigation happened in this frame. |
| 79 TEST_F(FrameNavigationStateTest, ErrorStateFrame) { | 80 TEST_F(FrameNavigationStateTest, ErrorStateFrame) { |
| 80 FrameNavigationState navigation_state; | 81 FrameNavigationState navigation_state; |
| 81 const long long frame_id1 = 23; | 82 const int64 frame_id1 = 23; |
| 82 const long long frame_id2 = 42; | 83 const int64 frame_id2 = 42; |
| 83 const GURL url("http://www.google.com/"); | 84 const GURL url("http://www.google.com/"); |
| 84 | 85 |
| 85 navigation_state.TrackFrame(frame_id1, url, true, contents()); | 86 navigation_state.TrackFrame(frame_id1, url, true, contents()); |
| 86 navigation_state.TrackFrame(frame_id2, url, false, contents()); | 87 navigation_state.TrackFrame(frame_id2, url, false, contents()); |
| 87 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); | 88 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); |
| 88 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2)); | 89 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2)); |
| 89 | 90 |
| 90 // After an error occurred, no further events should be sent. | 91 // After an error occurred, no further events should be sent. |
| 91 navigation_state.ErrorOccurredInFrame(frame_id2); | 92 navigation_state.ErrorOccurredInFrame(frame_id2); |
| 92 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); | 93 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); |
| 93 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); | 94 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); |
| 94 | 95 |
| 95 // Navigations to the "unreachable web data" URL should be ignored. | 96 // Navigations to the "unreachable web data" URL should be ignored. |
| 96 navigation_state.TrackFrame( | 97 navigation_state.TrackFrame( |
| 97 frame_id2, GURL(chrome::kUnreachableWebDataURL), false, contents()); | 98 frame_id2, GURL(chrome::kUnreachableWebDataURL), false, contents()); |
| 98 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); | 99 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); |
| 99 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); | 100 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); |
| 100 | 101 |
| 101 // However, when the frame navigates again, it should send events again. | 102 // However, when the frame navigates again, it should send events again. |
| 102 navigation_state.TrackFrame(frame_id2, url, false, contents()); | 103 navigation_state.TrackFrame(frame_id2, url, false, contents()); |
| 103 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); | 104 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id1)); |
| 104 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2)); | 105 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id2)); |
| 105 } | 106 } |
| OLD | NEW |