OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 4047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4058 registerMockedHttpURLLoad("push_state.html"); | 4058 registerMockedHttpURLLoad("push_state.html"); |
4059 TestStartStopCallbackWebViewClient client; | 4059 TestStartStopCallbackWebViewClient client; |
4060 FrameTestHelpers::WebViewHelper webViewHelper; | 4060 FrameTestHelpers::WebViewHelper webViewHelper; |
4061 webViewHelper.initializeAndLoad(m_baseURL + "push_state.html", true, 0, &cli
ent); | 4061 webViewHelper.initializeAndLoad(m_baseURL + "push_state.html", true, 0, &cli
ent); |
4062 runPendingTasks(); | 4062 runPendingTasks(); |
4063 | 4063 |
4064 EXPECT_EQ(client.startLoadingCount(), 2); | 4064 EXPECT_EQ(client.startLoadingCount(), 2); |
4065 EXPECT_EQ(client.stopLoadingCount(), 2); | 4065 EXPECT_EQ(client.stopLoadingCount(), 2); |
4066 } | 4066 } |
4067 | 4067 |
| 4068 class TestHistoryWebFrameClient : public WebFrameClient { |
| 4069 public: |
| 4070 TestHistoryWebFrameClient() |
| 4071 { |
| 4072 m_replacesCurrentHistoryItem = false; |
| 4073 m_frame = 0; |
| 4074 } |
| 4075 void didStartProvisionalLoad(WebFrame* frame) |
| 4076 { |
| 4077 WebDataSource* ds = frame->provisionalDataSource(); |
| 4078 m_replacesCurrentHistoryItem = ds->replacesCurrentHistoryItem(); |
| 4079 m_frame = frame; |
| 4080 } |
| 4081 |
| 4082 bool replacesCurrentHistoryItem() { return m_replacesCurrentHistoryItem; } |
| 4083 WebFrame* frame() { return m_frame; } |
| 4084 |
| 4085 private: |
| 4086 bool m_replacesCurrentHistoryItem; |
| 4087 WebFrame* m_frame; |
| 4088 }; |
| 4089 |
| 4090 // Test which ensures that the first navigation in a subframe will always |
| 4091 // result in history entry being replaced and not a new one added. |
| 4092 TEST_F(WebFrameTest, FirstFrameNavigationReplacesHistory) |
| 4093 { |
| 4094 registerMockedHttpURLLoad("history.html"); |
| 4095 registerMockedHttpURLLoad("find.html"); |
| 4096 |
| 4097 FrameTestHelpers::WebViewHelper webViewHelper; |
| 4098 TestHistoryWebFrameClient client; |
| 4099 webViewHelper.initializeAndLoad("about:blank", true, &client); |
| 4100 runPendingTasks(); |
| 4101 EXPECT_TRUE(client.replacesCurrentHistoryItem()); |
| 4102 |
| 4103 WebFrame* frame = webViewHelper.webView()->mainFrame(); |
| 4104 |
| 4105 FrameTestHelpers::loadFrame(frame, |
| 4106 "javascript:document.body.appendChild(document.createElement('iframe'))"
); |
| 4107 // Need to call runPendingTasks in order for the JavaScript above to be |
| 4108 // evaluated and executed. |
| 4109 runPendingTasks(); |
| 4110 WebFrame* iframe = frame->firstChild(); |
| 4111 EXPECT_EQ(client.frame(), iframe); |
| 4112 EXPECT_TRUE(client.replacesCurrentHistoryItem()); |
| 4113 |
| 4114 FrameTestHelpers::loadFrame(frame, |
| 4115 "javascript:window.frames[0].location.assign('" + m_baseURL + "history.h
tml')"); |
| 4116 runPendingTasks(); |
| 4117 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 4118 EXPECT_EQ(client.frame(), iframe); |
| 4119 EXPECT_TRUE(client.replacesCurrentHistoryItem()); |
| 4120 |
| 4121 FrameTestHelpers::loadFrame(frame, |
| 4122 "javascript:window.frames[0].location.assign('" + m_baseURL + "find.html
')"); |
| 4123 runPendingTasks(); |
| 4124 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 4125 EXPECT_EQ(client.frame(), iframe); |
| 4126 EXPECT_FALSE(client.replacesCurrentHistoryItem()); |
| 4127 |
| 4128 // Repeat the test, but start out the iframe with initial URL, which is not |
| 4129 // "about:blank". |
| 4130 FrameTestHelpers::loadFrame(frame, |
| 4131 "javascript:var f = document.createElement('iframe'); " |
| 4132 "f.src = '" + m_baseURL + "history.html';" |
| 4133 "document.body.appendChild(f)"); |
| 4134 runPendingTasks(); |
| 4135 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 4136 |
| 4137 iframe = frame->firstChild()->nextSibling(); |
| 4138 EXPECT_EQ(client.frame(), iframe); |
| 4139 EXPECT_TRUE(client.replacesCurrentHistoryItem()); |
| 4140 |
| 4141 FrameTestHelpers::loadFrame(frame, |
| 4142 "javascript:window.frames[1].location.assign('" + m_baseURL + "find.html
')"); |
| 4143 runPendingTasks(); |
| 4144 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 4145 EXPECT_EQ(client.frame(), iframe); |
| 4146 EXPECT_FALSE(client.replacesCurrentHistoryItem()); |
| 4147 } |
| 4148 |
4068 } // namespace | 4149 } // namespace |
OLD | NEW |