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

Side by Side Diff: chrome/browser/permissions/permission_manager_unittest.cc

Issue 2904623002: Disable permissions dialog in VR (Closed)
Patch Set: CancelPermissionRequest is removed Created 3 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/permissions/permission_manager.h" 5 #include "chrome/browser/permissions/permission_manager.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/permissions/permission_manager_factory.h" 10 #include "chrome/browser/permissions/permission_manager_factory.h"
11 #include "chrome/browser/permissions/permission_result.h" 11 #include "chrome/browser/permissions/permission_result.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "components/content_settings/core/browser/host_content_settings_map.h" 13 #include "components/content_settings/core/browser/host_content_settings_map.h"
14 #include "content/public/browser/permission_type.h" 14 #include "content/public/browser/permission_type.h"
15 #include "content/public/test/test_browser_thread_bundle.h" 15 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "content/public/test/test_renderer_host.h"
17 #include "device/vr/features/features.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 19
20 #if BUILDFLAG(ENABLE_VR)
21 #include "chrome/browser/android/vr_shell/vr_tab_helper.h"
22 #endif // BUILDFLAG(ENABLE_VR)
23
18 using blink::mojom::PermissionStatus; 24 using blink::mojom::PermissionStatus;
19 using content::PermissionType; 25 using content::PermissionType;
20 26
21 namespace { 27 namespace {
22 28
29 int kNoPendingOperation = -1;
30
23 class PermissionManagerTestingProfile final : public TestingProfile { 31 class PermissionManagerTestingProfile final : public TestingProfile {
24 public: 32 public:
25 PermissionManagerTestingProfile() {} 33 PermissionManagerTestingProfile() {}
26 ~PermissionManagerTestingProfile() override {} 34 ~PermissionManagerTestingProfile() override {}
27 35
28 PermissionManager* GetPermissionManager() override { 36 PermissionManager* GetPermissionManager() override {
29 return PermissionManagerFactory::GetForProfile(this); 37 return PermissionManagerFactory::GetForProfile(this);
30 } 38 }
31 39
32 DISALLOW_COPY_AND_ASSIGN(PermissionManagerTestingProfile); 40 DISALLOW_COPY_AND_ASSIGN(PermissionManagerTestingProfile);
33 }; 41 };
34 42
35 } // anonymous namespace 43 } // anonymous namespace
36 44
37 class PermissionManagerTest : public testing::Test { 45 class PermissionManagerTest : public content::RenderViewHostTestHarness {
38 public: 46 public:
39 void OnPermissionChange(PermissionStatus permission) { 47 void OnPermissionChange(PermissionStatus permission) {
40 callback_called_ = true; 48 callback_called_ = true;
41 callback_result_ = permission; 49 callback_result_ = permission;
42 } 50 }
43 51
44 protected: 52 protected:
45 PermissionManagerTest() 53 PermissionManagerTest()
46 : url_("https://example.com"), 54 : url_("https://example.com"),
47 other_url_("https://foo.com"), 55 other_url_("https://foo.com"),
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::ASK); 381 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::ASK);
374 GetHostContentSettingsMap()->SetContentSettingDefaultScope( 382 GetHostContentSettingsMap()->SetContentSettingDefaultScope(
375 url(), url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), 383 url(), url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(),
376 CONTENT_SETTING_ALLOW); 384 CONTENT_SETTING_ALLOW);
377 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::GRANTED); 385 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::GRANTED);
378 386
379 EXPECT_FALSE(callback_called()); 387 EXPECT_FALSE(callback_called());
380 388
381 GetPermissionManager()->UnsubscribePermissionStatusChange(subscription_id); 389 GetPermissionManager()->UnsubscribePermissionStatusChange(subscription_id);
382 } 390 }
391
392 TEST_F(PermissionManagerTest, SuppressPermissionRequests) {
393 content::WebContents* contents = web_contents();
394 EXPECT_NE(kNoPendingOperation,
395 GetPermissionManager()->RequestPermission(
396 PermissionType::GEOLOCATION, web_contents()->GetMainFrame(),
raymes 2017/05/31 23:10:08 nit: either use |contents| everywhere or web_conte
asimjour1 2017/06/06 17:58:56 Done.
397 url(), true,
398 base::Bind(&PermissionManagerTest::OnPermissionChange,
399 base::Unretained(this))));
400 EXPECT_TRUE(callback_called());
401 EXPECT_EQ(PermissionStatus::GRANTED, callback_result());
402
403 #if BUILDFLAG(ENABLE_VR)
404 vr_shell::VrTabHelper* vr_tab_helper =
405 vr_shell::VrTabHelper::FromWebContents(contents);
406
407 vr_tab_helper->SetIsInVr(true);
408 EXPECT_EQ(kNoPendingOperation,
409 GetPermissionManager()->RequestPermission(
410 PermissionType::GEOLOCATION, web_contents()->GetMainFrame(),
411 url(), true,
412 base::Bind(&PermissionManagerTest::OnPermissionChange,
413 base::Unretained(this))));
414 EXPECT_FALSE(callback_called());
415 EXPECT_NE(PermissionStatus::GRANTED, callback_result());
416
417 vr_tab_helper->SetIsInVr(false);
418 EXPECT_NE(kNoPendingOperation,
419 GetPermissionManager()->RequestPermission(
420 PermissionType::GEOLOCATION, web_contents()->GetMainFrame(),
421 url(), true,
422 base::Bind(&PermissionManagerTest::OnPermissionChange,
423 base::Unretained(this))));
424 EXPECT_TRUE(callback_called());
425 EXPECT_EQ(PermissionStatus::GRANTED, callback_result());
426 #endif // BUILDFLAG(ENABLE_VR)
427 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698