Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

Issue 1208143002: Move existing kSitePerProcess checks to a policy-oracle object (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@swapped_out_cmdline_checks
Patch Set: Partial fixes to Nasko's comments. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 14 matching lines...) Expand all
25 #include "content/common/view_messages.h" 25 #include "content/common/view_messages.h"
26 #include "content/public/browser/navigation_details.h" 26 #include "content/public/browser/navigation_details.h"
27 #include "content/public/browser/notification_registrar.h" 27 #include "content/public/browser/notification_registrar.h"
28 #include "content/public/browser/notification_types.h" 28 #include "content/public/browser/notification_types.h"
29 #include "content/public/browser/render_view_host.h" 29 #include "content/public/browser/render_view_host.h"
30 #include "content/public/browser/web_contents_delegate.h" 30 #include "content/public/browser/web_contents_delegate.h"
31 #include "content/public/browser/web_contents_observer.h" 31 #include "content/public/browser/web_contents_observer.h"
32 #include "content/public/common/content_switches.h" 32 #include "content/public/common/content_switches.h"
33 #include "content/public/common/page_state.h" 33 #include "content/public/common/page_state.h"
34 #include "content/public/common/page_type.h" 34 #include "content/public/common/page_type.h"
35 #include "content/public/common/site_isolation_policy.h"
35 #include "content/public/common/url_constants.h" 36 #include "content/public/common/url_constants.h"
36 #include "content/public/test/mock_render_process_host.h" 37 #include "content/public/test/mock_render_process_host.h"
37 #include "content/public/test/test_notification_tracker.h" 38 #include "content/public/test/test_notification_tracker.h"
38 #include "content/public/test/test_utils.h" 39 #include "content/public/test/test_utils.h"
39 #include "content/test/test_render_frame_host.h" 40 #include "content/test/test_render_frame_host.h"
40 #include "content/test/test_render_view_host.h" 41 #include "content/test/test_render_view_host.h"
41 #include "content/test/test_web_contents.h" 42 #include "content/test/test_web_contents.h"
42 #include "net/base/net_util.h" 43 #include "net/base/net_util.h"
43 #include "skia/ext/platform_canvas.h" 44 #include "skia/ext/platform_canvas.h"
44 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); 2077 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
2077 EXPECT_EQ(2, controller.GetEntryCount()); 2078 EXPECT_EQ(2, controller.GetEntryCount());
2078 EXPECT_EQ(entry, details.entry); 2079 EXPECT_EQ(entry, details.entry);
2079 2080
2080 // New entry should refer to the new page, but the old URL (entries only 2081 // New entry should refer to the new page, but the old URL (entries only
2081 // reflect the toplevel URL). 2082 // reflect the toplevel URL).
2082 EXPECT_EQ(url1, entry->GetURL()); 2083 EXPECT_EQ(url1, entry->GetURL());
2083 EXPECT_EQ(params.page_id, entry->GetPageID()); 2084 EXPECT_EQ(params.page_id, entry->GetPageID());
2084 2085
2085 // Verify subframe entries if we're in --site-per-process mode. 2086 // Verify subframe entries if we're in --site-per-process mode.
2086 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2087 if (SiteIsolationPolicy::AreAllSitesIsolatedForTesting()) {
2087 switches::kSitePerProcess)) {
2088 // The entry should have a subframe FrameNavigationEntry. 2088 // The entry should have a subframe FrameNavigationEntry.
2089 ASSERT_EQ(1U, entry->root_node()->children.size()); 2089 ASSERT_EQ(1U, entry->root_node()->children.size());
2090 EXPECT_EQ(url2, entry->root_node()->children[0]->frame_entry->url()); 2090 EXPECT_EQ(url2, entry->root_node()->children[0]->frame_entry->url());
2091 } else { 2091 } else {
2092 // There are no subframe FrameNavigationEntries by default. 2092 // There are no subframe FrameNavigationEntries by default.
2093 EXPECT_EQ(0U, entry->root_node()->children.size()); 2093 EXPECT_EQ(0U, entry->root_node()->children.size());
2094 } 2094 }
2095 } 2095 }
2096 2096
2097 // Auto subframes are ones the page loads automatically like ads. They should 2097 // Auto subframes are ones the page loads automatically like ads. They should
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2134 2134
2135 // There should still be only one entry. 2135 // There should still be only one entry.
2136 EXPECT_EQ(1, controller.GetEntryCount()); 2136 EXPECT_EQ(1, controller.GetEntryCount());
2137 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); 2137 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
2138 EXPECT_EQ(url1, entry->GetURL()); 2138 EXPECT_EQ(url1, entry->GetURL());
2139 EXPECT_EQ(1, entry->GetPageID()); 2139 EXPECT_EQ(1, entry->GetPageID());
2140 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get(); 2140 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get();
2141 EXPECT_EQ(url1, root_entry->url()); 2141 EXPECT_EQ(url1, root_entry->url());
2142 2142
2143 // Verify subframe entries if we're in --site-per-process mode. 2143 // Verify subframe entries if we're in --site-per-process mode.
2144 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2144 if (SiteIsolationPolicy::AreAllSitesIsolatedForTesting()) {
2145 switches::kSitePerProcess)) {
2146 // The entry should now have a subframe FrameNavigationEntry. 2145 // The entry should now have a subframe FrameNavigationEntry.
2147 ASSERT_EQ(1U, entry->root_node()->children.size()); 2146 ASSERT_EQ(1U, entry->root_node()->children.size());
2148 FrameNavigationEntry* frame_entry = 2147 FrameNavigationEntry* frame_entry =
2149 entry->root_node()->children[0]->frame_entry.get(); 2148 entry->root_node()->children[0]->frame_entry.get();
2150 EXPECT_EQ(url2, frame_entry->url()); 2149 EXPECT_EQ(url2, frame_entry->url());
2151 } else { 2150 } else {
2152 // There are no subframe FrameNavigationEntries by default. 2151 // There are no subframe FrameNavigationEntries by default.
2153 EXPECT_EQ(0U, entry->root_node()->children.size()); 2152 EXPECT_EQ(0U, entry->root_node()->children.size());
2154 } 2153 }
2155 2154
(...skipping 24 matching lines...) Expand all
2180 2179
2181 // There should still be only one entry, mostly unchanged. 2180 // There should still be only one entry, mostly unchanged.
2182 EXPECT_EQ(1, controller.GetEntryCount()); 2181 EXPECT_EQ(1, controller.GetEntryCount());
2183 EXPECT_EQ(entry, controller.GetLastCommittedEntry()); 2182 EXPECT_EQ(entry, controller.GetLastCommittedEntry());
2184 EXPECT_EQ(url1, entry->GetURL()); 2183 EXPECT_EQ(url1, entry->GetURL());
2185 EXPECT_EQ(1, entry->GetPageID()); 2184 EXPECT_EQ(1, entry->GetPageID());
2186 EXPECT_EQ(root_entry, entry->root_node()->frame_entry.get()); 2185 EXPECT_EQ(root_entry, entry->root_node()->frame_entry.get());
2187 EXPECT_EQ(url1, root_entry->url()); 2186 EXPECT_EQ(url1, root_entry->url());
2188 2187
2189 // Verify subframe entries if we're in --site-per-process mode. 2188 // Verify subframe entries if we're in --site-per-process mode.
2190 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2189 if (SiteIsolationPolicy::AreAllSitesIsolatedForTesting()) {
2191 switches::kSitePerProcess)) {
2192 // The entry should now have 2 subframe FrameNavigationEntries. 2190 // The entry should now have 2 subframe FrameNavigationEntries.
2193 ASSERT_EQ(2U, entry->root_node()->children.size()); 2191 ASSERT_EQ(2U, entry->root_node()->children.size());
2194 FrameNavigationEntry* new_frame_entry = 2192 FrameNavigationEntry* new_frame_entry =
2195 entry->root_node()->children[1]->frame_entry.get(); 2193 entry->root_node()->children[1]->frame_entry.get();
2196 EXPECT_EQ(url3, new_frame_entry->url()); 2194 EXPECT_EQ(url3, new_frame_entry->url());
2197 } else { 2195 } else {
2198 // There are no subframe FrameNavigationEntries by default. 2196 // There are no subframe FrameNavigationEntries by default.
2199 EXPECT_EQ(0U, entry->root_node()->children.size()); 2197 EXPECT_EQ(0U, entry->root_node()->children.size());
2200 } 2198 }
2201 2199
(...skipping 28 matching lines...) Expand all
2230 2228
2231 // There should still be only one entry, mostly unchanged. 2229 // There should still be only one entry, mostly unchanged.
2232 EXPECT_EQ(1, controller.GetEntryCount()); 2230 EXPECT_EQ(1, controller.GetEntryCount());
2233 EXPECT_EQ(entry, controller.GetLastCommittedEntry()); 2231 EXPECT_EQ(entry, controller.GetLastCommittedEntry());
2234 EXPECT_EQ(url1, entry->GetURL()); 2232 EXPECT_EQ(url1, entry->GetURL());
2235 EXPECT_EQ(1, entry->GetPageID()); 2233 EXPECT_EQ(1, entry->GetPageID());
2236 EXPECT_EQ(root_entry, entry->root_node()->frame_entry.get()); 2234 EXPECT_EQ(root_entry, entry->root_node()->frame_entry.get());
2237 EXPECT_EQ(url1, root_entry->url()); 2235 EXPECT_EQ(url1, root_entry->url());
2238 2236
2239 // Verify subframe entries if we're in --site-per-process mode. 2237 // Verify subframe entries if we're in --site-per-process mode.
2240 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2238 if (SiteIsolationPolicy::AreAllSitesIsolatedForTesting()) {
2241 switches::kSitePerProcess)) {
2242 // The entry should now have a nested FrameNavigationEntry. 2239 // The entry should now have a nested FrameNavigationEntry.
2243 EXPECT_EQ(2U, entry->root_node()->children.size()); 2240 EXPECT_EQ(2U, entry->root_node()->children.size());
2244 ASSERT_EQ(1U, entry->root_node()->children[0]->children.size()); 2241 ASSERT_EQ(1U, entry->root_node()->children[0]->children.size());
2245 FrameNavigationEntry* new_frame_entry = 2242 FrameNavigationEntry* new_frame_entry =
2246 entry->root_node()->children[0]->children[0]->frame_entry.get(); 2243 entry->root_node()->children[0]->children[0]->frame_entry.get();
2247 EXPECT_EQ(url4, new_frame_entry->url()); 2244 EXPECT_EQ(url4, new_frame_entry->url());
2248 } else { 2245 } else {
2249 // There are no subframe FrameNavigationEntries by default. 2246 // There are no subframe FrameNavigationEntries by default.
2250 EXPECT_EQ(0U, entry->root_node()->children.size()); 2247 EXPECT_EQ(0U, entry->root_node()->children.size());
2251 } 2248 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2304 2301
2305 // This should generate a new entry. 2302 // This should generate a new entry.
2306 LoadCommittedDetails details; 2303 LoadCommittedDetails details;
2307 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); 2304 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2308 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry(); 2305 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry();
2309 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2306 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2310 navigation_entry_committed_counter_ = 0; 2307 navigation_entry_committed_counter_ = 0;
2311 EXPECT_EQ(2, controller.GetEntryCount()); 2308 EXPECT_EQ(2, controller.GetEntryCount());
2312 2309
2313 // Verify subframe entries if we're in --site-per-process mode. 2310 // Verify subframe entries if we're in --site-per-process mode.
2314 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2311 if (SiteIsolationPolicy::AreAllSitesIsolatedForTesting()) {
2315 switches::kSitePerProcess)) {
2316 // The entry should have a subframe FrameNavigationEntry. 2312 // The entry should have a subframe FrameNavigationEntry.
2317 ASSERT_EQ(1U, entry2->root_node()->children.size()); 2313 ASSERT_EQ(1U, entry2->root_node()->children.size());
2318 EXPECT_EQ(url2, entry2->root_node()->children[0]->frame_entry->url()); 2314 EXPECT_EQ(url2, entry2->root_node()->children[0]->frame_entry->url());
2319 } else { 2315 } else {
2320 // There are no subframe FrameNavigationEntries by default. 2316 // There are no subframe FrameNavigationEntries by default.
2321 EXPECT_EQ(0U, entry2->root_node()->children.size()); 2317 EXPECT_EQ(0U, entry2->root_node()->children.size());
2322 } 2318 }
2323 2319
2324 // Second manual subframe navigation should also make a new entry. 2320 // Second manual subframe navigation should also make a new entry.
2325 const GURL url3("http://foo3"); 2321 const GURL url3("http://foo3");
2326 params.page_id = 3; 2322 params.page_id = 3;
2327 params.nav_entry_id = 0; 2323 params.nav_entry_id = 0;
2328 params.did_create_new_entry = true; 2324 params.did_create_new_entry = true;
2329 params.url = url3; 2325 params.url = url3;
2330 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2326 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2331 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details)); 2327 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2332 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2328 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2333 navigation_entry_committed_counter_ = 0; 2329 navigation_entry_committed_counter_ = 0;
2334 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry(); 2330 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry();
2335 EXPECT_EQ(3, controller.GetEntryCount()); 2331 EXPECT_EQ(3, controller.GetEntryCount());
2336 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2332 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2337 2333
2338 // Verify subframe entries if we're in --site-per-process mode. 2334 // Verify subframe entries if we're in --site-per-process mode.
2339 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 2335 if (SiteIsolationPolicy::AreAllSitesIsolatedForTesting()) {
2340 switches::kSitePerProcess)) {
2341 // The entry should have a subframe FrameNavigationEntry. 2336 // The entry should have a subframe FrameNavigationEntry.
2342 ASSERT_EQ(1U, entry3->root_node()->children.size()); 2337 ASSERT_EQ(1U, entry3->root_node()->children.size());
2343 EXPECT_EQ(url3, entry3->root_node()->children[0]->frame_entry->url()); 2338 EXPECT_EQ(url3, entry3->root_node()->children[0]->frame_entry->url());
2344 } else { 2339 } else {
2345 // There are no subframe FrameNavigationEntries by default. 2340 // There are no subframe FrameNavigationEntries by default.
2346 EXPECT_EQ(0U, entry3->root_node()->children.size()); 2341 EXPECT_EQ(0U, entry3->root_node()->children.size());
2347 } 2342 }
2348 2343
2349 // Go back one. 2344 // Go back one.
2350 controller.GoBack(); 2345 controller.GoBack();
(...skipping 2652 matching lines...) Expand 10 before | Expand all | Expand 10 after
5003 // means that occasionally a navigation conflict will end up with one entry 4998 // means that occasionally a navigation conflict will end up with one entry
5004 // bubbling to the end of the entry list, but that's the least-bad option. 4999 // bubbling to the end of the entry list, but that's the least-bad option.
5005 EXPECT_EQ(3, controller.GetEntryCount()); 5000 EXPECT_EQ(3, controller.GetEntryCount());
5006 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 5001 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
5007 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL()); 5002 EXPECT_EQ(url_a, controller.GetEntryAtIndex(0)->GetURL());
5008 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL()); 5003 EXPECT_EQ(url_c, controller.GetEntryAtIndex(1)->GetURL());
5009 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL()); 5004 EXPECT_EQ(url_b, controller.GetEntryAtIndex(2)->GetURL());
5010 } 5005 }
5011 5006
5012 } // namespace content 5007 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698