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

Side by Side Diff: chrome/browser/chromeos/extensions/extension_tab_util_delegate_chromeos_unittest.cc

Issue 2858643002: PS - Filtering activeTab URL (Closed)
Patch Set: ExtensionBuilder in test Created 3 years, 7 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/chromeos/extensions/extension_tab_util_delegate_chromeo s.h" 5 #include "chrome/browser/chromeos/extensions/extension_tab_util_delegate_chromeo s.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "chromeos/login/login_state.h" 9 #include "chromeos/login/login_state.h"
10 #include "chromeos/login/scoped_test_public_session_login_state.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/extension_builder.h"
13 #include "extensions/common/value_builder.h"
10 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
11 15
12 namespace extensions { 16 namespace extensions {
13 17
14 namespace { 18 namespace {
15 19
20 const char kWhitelistedId[] = "cbkkbcmdlboombapidmoeolnmdacpkch";
21 // Use an extension ID that will never be whitelisted.
22 const char kNonWhitelistedId[] = "bogus";
23
16 const char kTestUrl[] = "http://www.foo.bar/baz?key=val"; 24 const char kTestUrl[] = "http://www.foo.bar/baz?key=val";
17 const char kFilteredUrl[] = "http://www.foo.bar/"; 25 const char kFilteredUrl[] = "http://www.foo.bar/";
18 26
27 scoped_refptr<Extension> CreateExtension(const std::string& id) {
28 return ExtensionBuilder()
29 .SetManifest(
30 DictionaryBuilder().Set("name", "test").Set("version", "0.1").Build())
31 .SetID(id)
32 .Build();
33 }
34
19 } // namespace 35 } // namespace
20 36
21 class ExtensionTabUtilDelegateChromeOSTest : public testing::Test { 37 class ExtensionTabUtilDelegateChromeOSTest : public testing::Test {
22 protected: 38 protected:
23 void SetUp() override; 39 void SetUp() override;
24 40
25 ExtensionTabUtilDelegateChromeOS delegate_; 41 ExtensionTabUtilDelegateChromeOS delegate_;
26 api::tabs::Tab tab_; 42 api::tabs::Tab tab_;
27 }; 43 };
28 44
29 void ExtensionTabUtilDelegateChromeOSTest::SetUp() { 45 void ExtensionTabUtilDelegateChromeOSTest::SetUp() {
30 tab_.url.reset(new std::string(kTestUrl)); 46 tab_.url.reset(new std::string(kTestUrl));
31 } 47 }
32 48
33 TEST_F(ExtensionTabUtilDelegateChromeOSTest, NoFilteringOutsidePublicSession) { 49 TEST_F(ExtensionTabUtilDelegateChromeOSTest,
50 NoFilteringOutsidePublicSessionForWhitelisted) {
34 ASSERT_FALSE(chromeos::LoginState::IsInitialized()); 51 ASSERT_FALSE(chromeos::LoginState::IsInitialized());
35 52
36 delegate_.ScrubTabForExtension(nullptr, nullptr, &tab_); 53 auto extension = CreateExtension(kWhitelistedId);
54 delegate_.ScrubTabForExtension(extension.get(), nullptr, &tab_);
37 EXPECT_EQ(kTestUrl, *tab_.url); 55 EXPECT_EQ(kTestUrl, *tab_.url);
38 } 56 }
39 57
40 TEST_F(ExtensionTabUtilDelegateChromeOSTest, ScrubURL) { 58 TEST_F(ExtensionTabUtilDelegateChromeOSTest,
41 // Set Public Session state. 59 NoFilteringOutsidePublicSessionForNonWhitelisted) {
42 chromeos::LoginState::Initialize(); 60 ASSERT_FALSE(chromeos::LoginState::IsInitialized());
43 chromeos::LoginState::Get()->SetLoggedInState(
44 chromeos::LoginState::LOGGED_IN_ACTIVE,
45 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT);
46 61
47 delegate_.ScrubTabForExtension(nullptr, nullptr, &tab_); 62 auto extension = CreateExtension(kNonWhitelistedId);
63 delegate_.ScrubTabForExtension(extension.get(), nullptr, &tab_);
64 EXPECT_EQ(kTestUrl, *tab_.url);
65 }
66
67 TEST_F(ExtensionTabUtilDelegateChromeOSTest,
68 NoFilteringInsidePublicSessionForWhitelisted) {
69 chromeos::ScopedTestPublicSessionLoginState state;
70
71 auto extension = CreateExtension(kWhitelistedId);
72 delegate_.ScrubTabForExtension(extension.get(), nullptr, &tab_);
73 EXPECT_EQ(kTestUrl, *tab_.url);
74 }
75
76 TEST_F(ExtensionTabUtilDelegateChromeOSTest,
77 FilterInsidePublicSessionNonWhitelisted) {
78 chromeos::ScopedTestPublicSessionLoginState state;
79
80 auto extension = CreateExtension(kNonWhitelistedId);
81 delegate_.ScrubTabForExtension(extension.get(), nullptr, &tab_);
48 EXPECT_EQ(kFilteredUrl, *tab_.url); 82 EXPECT_EQ(kFilteredUrl, *tab_.url);
49
50 // Reset state at the end of test.
51 chromeos::LoginState::Shutdown();
52 } 83 }
53 84
54 } // namespace extensions 85 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698