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

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

Issue 855883002: Allow universal access from file if flag is set and url is file scheme. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit tests Created 5 years, 11 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 3187 matching lines...) Expand 10 before | Expand all | Expand 10 after
3198 3198
3199 // Don't believe the renderer if it claims a cross-origin navigation is 3199 // Don't believe the renderer if it claims a cross-origin navigation is
3200 // in-page. 3200 // in-page.
3201 const GURL different_origin_url("http://www.example.com"); 3201 const GURL different_origin_url("http://www.example.com");
3202 MockRenderProcessHost* rph = 3202 MockRenderProcessHost* rph =
3203 static_cast<MockRenderProcessHost*>(main_test_rfh()->GetProcess()); 3203 static_cast<MockRenderProcessHost*>(main_test_rfh()->GetProcess());
3204 EXPECT_EQ(0, rph->bad_msg_count()); 3204 EXPECT_EQ(0, rph->bad_msg_count());
3205 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true, 3205 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true,
3206 main_test_rfh())); 3206 main_test_rfh()));
3207 EXPECT_EQ(1, rph->bad_msg_count()); 3207 EXPECT_EQ(1, rph->bad_msg_count());
3208
3209 // Test allow_universal_access_from_file_urls flag
Charlie Reis 2015/01/23 06:53:37 nit: End with period.
nhu 2015/01/23 13:41:13 Done.
3210 WebPreferences prefs =
3211 main_test_rfh()->GetRenderViewHost()->GetWebkitPreferences();
Charlie Reis 2015/01/23 06:53:37 test_rvh() (here and below)
nhu 2015/01/23 13:41:13 Done.
3212 EXPECT_EQ(false, prefs.allow_universal_access_from_file_urls);
3213 prefs.allow_universal_access_from_file_urls = true;
3214 main_test_rfh()->GetRenderViewHost()->UpdateWebkitPreferences(prefs);
3215 prefs =
3216 main_test_rfh()->GetRenderViewHost()->GetWebkitPreferences();
3217 EXPECT_EQ(true, prefs.allow_universal_access_from_file_urls);
3218 // Don't hornor allow_universal_access_from_file_urls if existing URL is
Charlie Reis 2015/01/23 06:53:37 honor
nhu 2015/01/23 13:41:13 Done.
3219 // not file scheme.
3220 EXPECT_EQ(1, rph->bad_msg_count());
3221 EXPECT_FALSE(controller.IsURLInPageNavigation(different_origin_url, true,
3222 main_test_rfh()));
3223 EXPECT_EQ(2, rph->bad_msg_count());
3224 // Allow in page navigation if existing URL is file scheme.
Charlie Reis 2015/01/23 06:53:37 Move this case above the bad_msg_count case, so th
nhu 2015/01/23 13:41:13 It makes sense. I reordered them. Does it look bet
3225 const GURL file_url("file:///foo/index.html");
3226 main_test_rfh()->SendNavigate(0, file_url);
3227 EXPECT_EQ(2, rph->bad_msg_count());
3228 EXPECT_TRUE(controller.IsURLInPageNavigation(different_origin_url, true,
3229 main_test_rfh()));
3230 EXPECT_EQ(2, rph->bad_msg_count());
3208 } 3231 }
3209 3232
3210 // Some pages can have subframes with the same base URL (minus the reference) as 3233 // Some pages can have subframes with the same base URL (minus the reference) as
3211 // the main page. Even though this is hard, it can happen, and we don't want 3234 // the main page. Even though this is hard, it can happen, and we don't want
3212 // these subframe navigations to affect the toplevel document. They should 3235 // these subframe navigations to affect the toplevel document. They should
3213 // instead be ignored. http://crbug.com/5585 3236 // instead be ignored. http://crbug.com/5585
3214 TEST_F(NavigationControllerTest, SameSubframe) { 3237 TEST_F(NavigationControllerTest, SameSubframe) {
3215 NavigationControllerImpl& controller = controller_impl(); 3238 NavigationControllerImpl& controller = controller_impl();
3216 // Navigate the main frame. 3239 // Navigate the main frame.
3217 const GURL url("http://www.google.com/"); 3240 const GURL url("http://www.google.com/");
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
4416 params.post_id = -1; 4439 params.post_id = -1;
4417 contents()->GetMainFrame()->SendNavigateWithParams(&params); 4440 contents()->GetMainFrame()->SendNavigateWithParams(&params);
4418 4441
4419 // Now reload. replaceState overrides the POST, so we should not show a 4442 // Now reload. replaceState overrides the POST, so we should not show a
4420 // repost warning dialog. 4443 // repost warning dialog.
4421 controller_impl().Reload(true); 4444 controller_impl().Reload(true);
4422 EXPECT_EQ(0, delegate->repost_form_warning_count()); 4445 EXPECT_EQ(0, delegate->repost_form_warning_count());
4423 } 4446 }
4424 4447
4425 } // namespace content 4448 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698