Index: chrome/browser/extensions/extension_webnavigation_unittest.cc |
diff --git a/chrome/browser/extensions/extension_webnavigation_unittest.cc b/chrome/browser/extensions/extension_webnavigation_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..906a8a9017913164bf01c3a11199603fd5ea14cb |
--- /dev/null |
+++ b/chrome/browser/extensions/extension_webnavigation_unittest.cc |
@@ -0,0 +1,68 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+// Tests common functionality used by the Chrome Extensions webNavigation API |
+// implementation. |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+#include "base/values.h" |
+#include "chrome/browser/browser_thread.h" |
+#include "chrome/browser/extensions/extension_webnavigation_api.h" |
+#include "chrome/browser/renderer_host/test/test_render_view_host.h" |
+#include "chrome/browser/tab_contents/test_tab_contents.h" |
+#include "chrome/test/testing_profile.h" |
+ |
+class FrameNavigationStateTest : public RenderViewHostTestHarness { |
+ public: |
+ FrameNavigationStateTest() |
+ : RenderViewHostTestHarness(), |
+ ui_thread_(BrowserThread::UI, &message_loop_) { |
+ } |
+ |
+ private: |
+ |
Paweł Hajdan Jr.
2010/10/27 10:03:02
nit: Remove empty line.
|
+ BrowserThread ui_thread_; |
+}; |
+ |
+// Test that a frame is correctly tracked, and removed once the tab contents |
+// goes away. |
+TEST_F(FrameNavigationStateTest, TrackFrame) { |
+ FrameNavigationState navigation_state; |
+ TestTabContents* tab_contents = |
Paweł Hajdan Jr.
2010/10/27 10:03:02
nit: How about a scoped_ptr to make sure this won'
|
+ new TestTabContents(profile(), contents()->GetSiteInstance()); |
+ const long long frame_id = 42; |
+ const GURL url("http://www.google.com/"); |
+ |
+ EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); |
+ navigation_state.TrackFrame(frame_id, url, true, tab_contents); |
+ EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); |
+ |
+ // Deleting the tab contents should also remove all state of its frames. |
+ delete tab_contents; |
+ EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); |
+} |
+ |
+// Test that no events can be sent for a frame after an error occurred, but |
+// before a new navigation happened in this frame. |
+TEST_F(FrameNavigationStateTest, ErrorState) { |
+ FrameNavigationState navigation_state; |
+ TestTabContents* tab_contents = |
Paweł Hajdan Jr.
2010/10/27 10:03:02
nit: Same here.
|
+ new TestTabContents(profile(), contents()->GetSiteInstance()); |
+ const long long frame_id = 42; |
+ const GURL url("http://www.google.com/"); |
+ const GURL url2("http://mail.google.com/"); |
+ |
+ navigation_state.TrackFrame(frame_id, url, true, tab_contents); |
+ EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); |
+ |
+ // After an error occurred, no further events should be sent. |
+ navigation_state.ErrorOccurredInFrame(frame_id); |
+ EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); |
+ |
+ // However, when the frame navigates to another URL, it should send events |
+ // again. |
+ navigation_state.TrackFrame(frame_id, url2, true, tab_contents); |
yzshen
2010/10/27 17:43:38
What if the error happens in a subframe, and then
|
+ EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); |
+} |