OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Tests common functionality used by the Chrome Extensions webNavigation API | |
6 // implementation. | |
7 | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 #include "base/values.h" | |
11 #include "chrome/browser/browser_thread.h" | |
12 #include "chrome/browser/extensions/extension_webnavigation_api.h" | |
13 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | |
14 #include "chrome/browser/tab_contents/test_tab_contents.h" | |
15 #include "chrome/test/testing_profile.h" | |
16 | |
17 class FrameNavigationStateTest : public RenderViewHostTestHarness { | |
18 public: | |
19 FrameNavigationStateTest() | |
20 : RenderViewHostTestHarness(), | |
21 ui_thread_(BrowserThread::UI, &message_loop_) { | |
22 } | |
23 | |
24 private: | |
25 | |
Paweł Hajdan Jr.
2010/10/27 10:03:02
nit: Remove empty line.
| |
26 BrowserThread ui_thread_; | |
27 }; | |
28 | |
29 // Test that a frame is correctly tracked, and removed once the tab contents | |
30 // goes away. | |
31 TEST_F(FrameNavigationStateTest, TrackFrame) { | |
32 FrameNavigationState navigation_state; | |
33 TestTabContents* tab_contents = | |
Paweł Hajdan Jr.
2010/10/27 10:03:02
nit: How about a scoped_ptr to make sure this won'
| |
34 new TestTabContents(profile(), contents()->GetSiteInstance()); | |
35 const long long frame_id = 42; | |
36 const GURL url("http://www.google.com/"); | |
37 | |
38 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); | |
39 navigation_state.TrackFrame(frame_id, url, true, tab_contents); | |
40 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); | |
41 | |
42 // Deleting the tab contents should also remove all state of its frames. | |
43 delete tab_contents; | |
44 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); | |
45 } | |
46 | |
47 // Test that no events can be sent for a frame after an error occurred, but | |
48 // before a new navigation happened in this frame. | |
49 TEST_F(FrameNavigationStateTest, ErrorState) { | |
50 FrameNavigationState navigation_state; | |
51 TestTabContents* tab_contents = | |
Paweł Hajdan Jr.
2010/10/27 10:03:02
nit: Same here.
| |
52 new TestTabContents(profile(), contents()->GetSiteInstance()); | |
53 const long long frame_id = 42; | |
54 const GURL url("http://www.google.com/"); | |
55 const GURL url2("http://mail.google.com/"); | |
56 | |
57 navigation_state.TrackFrame(frame_id, url, true, tab_contents); | |
58 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); | |
59 | |
60 // After an error occurred, no further events should be sent. | |
61 navigation_state.ErrorOccurredInFrame(frame_id); | |
62 EXPECT_FALSE(navigation_state.CanSendEvents(frame_id)); | |
63 | |
64 // However, when the frame navigates to another URL, it should send events | |
65 // again. | |
66 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
| |
67 EXPECT_TRUE(navigation_state.CanSendEvents(frame_id)); | |
68 } | |
OLD | NEW |