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

Side by Side Diff: chrome/common/extensions/api/common_extension_api_unittest.cc

Issue 2255613003: Introduce session type parameter to extension features (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduce session type parameter to extension features Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "extensions/common/extension_api.h" 5 #include "extensions/common/extension_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
22 #include "chrome/common/extensions/extension_features_unittest.h" 22 #include "chrome/common/extensions/extension_features_unittest.h"
23 #include "extensions/common/extension.h" 23 #include "extensions/common/extension.h"
24 #include "extensions/common/extension_builder.h" 24 #include "extensions/common/extension_builder.h"
25 #include "extensions/common/features/feature_session_type.h"
25 #include "extensions/common/features/simple_feature.h" 26 #include "extensions/common/features/simple_feature.h"
26 #include "extensions/common/manifest.h" 27 #include "extensions/common/manifest.h"
27 #include "extensions/common/manifest_constants.h" 28 #include "extensions/common/manifest_constants.h"
28 #include "extensions/common/test_util.h" 29 #include "extensions/common/test_util.h"
29 #include "extensions/common/value_builder.h" 30 #include "extensions/common/value_builder.h"
30 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
31 32
32 namespace extensions { 33 namespace extensions {
33 34
34 namespace { 35 namespace {
35 36
36 const char* const kTestFeatures[] = { 37 const char* const kTestFeatures[] = {
37 "test1", "test2", "test3", "test4", "test5", 38 "test1", "test2", "test3", "test4", "test5",
38 "test6", "test7", "parent1", "parent2", "parent3", 39 "test6", "test7", "parent1", "parent2", "parent3",
39 }; 40 };
40 41
42 const char* const kSessionTypeTestFeatures[] = {
43 "test1", "kiosk_only", "non_kiosk", "multiple_session_types",
44 "empty_session_types"};
45
46 struct FeatureSessionTypesTestData {
47 std::string api_name;
48 bool expect_available;
49 FeatureSessionType current_session_type;
50 };
51
41 class TestExtensionAPI : public ExtensionAPI { 52 class TestExtensionAPI : public ExtensionAPI {
42 public: 53 public:
43 TestExtensionAPI() {} 54 TestExtensionAPI() {}
44 ~TestExtensionAPI() override {} 55 ~TestExtensionAPI() override {}
45 56
46 void add_fake_schema(const std::string& name) { fake_schemas_.insert(name); } 57 void add_fake_schema(const std::string& name) { fake_schemas_.insert(name); }
47 58
48 private: 59 private:
49 bool IsKnownAPI(const std::string& name, ExtensionsClient* client) override { 60 bool IsKnownAPI(const std::string& name, ExtensionsClient* client) override {
50 return fake_schemas_.count(name) != 0; 61 return fake_schemas_.count(name) != 0;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 ASSERT_TRUE(test_feature); 285 ASSERT_TRUE(test_feature);
275 EXPECT_EQ(test_data[i].expect_is_available, 286 EXPECT_EQ(test_data[i].expect_is_available,
276 api.IsAnyFeatureAvailableToContext(*test_feature, 287 api.IsAnyFeatureAvailableToContext(*test_feature,
277 test_data[i].extension, 288 test_data[i].extension,
278 test_data[i].context, 289 test_data[i].context,
279 test_data[i].url)) 290 test_data[i].url))
280 << i; 291 << i;
281 } 292 }
282 } 293 }
283 294
295 TEST(ExtensionAPITest, SessionTypeFeature) {
296 const std::vector<FeatureSessionTypesTestData> kTestData(
297 {{"kiosk_only", true, FeatureSessionType::KIOSK},
298 {"kiosk_only", false, FeatureSessionType::REGULAR},
299 {"kiosk_only", false, FeatureSessionType::UNKNOWN},
300 {"non_kiosk", false, FeatureSessionType::KIOSK},
301 {"non_kiosk", true, FeatureSessionType::REGULAR},
302 {"non_kiosk", false, FeatureSessionType::UNKNOWN},
303 {"multiple_session_types", true, FeatureSessionType::KIOSK},
304 {"multiple_session_types", true, FeatureSessionType::REGULAR},
305 {"multiple_session_types", false, FeatureSessionType::UNKNOWN},
306 {"empty_session_types", true, FeatureSessionType::KIOSK},
307 {"empty_session_types", true, FeatureSessionType::REGULAR},
308 {"empty_session_types", true, FeatureSessionType::UNKNOWN},
309 {"test1", true, FeatureSessionType::KIOSK},
310 {"test1", true, FeatureSessionType::REGULAR},
311 {"test1", true, FeatureSessionType::UNKNOWN}});
312
313 UnittestFeatureProvider api_feature_provider;
314
315 for (const auto& test : kTestData) {
316 TestExtensionAPI api;
317 api.RegisterDependencyProvider("api", &api_feature_provider);
318 for (const auto& key : kSessionTypeTestFeatures)
319 api.add_fake_schema(key);
320 ExtensionAPI::OverrideSharedInstanceForTest scope(&api);
321
322 std::unique_ptr<base::AutoReset<FeatureSessionType>> current_session(
323 ScopedCurrentFeatureSessionType(test.current_session_type));
324 EXPECT_EQ(test.expect_available,
325 api.IsAvailable(test.api_name, NULL,
326 Feature::BLESSED_EXTENSION_CONTEXT, GURL())
327 .is_available())
328 << "Test case (" << test.api_name << ", "
329 << static_cast<int>(test.current_session_type) << ").";
330 }
331 }
332
284 TEST(ExtensionAPITest, LazyGetSchema) { 333 TEST(ExtensionAPITest, LazyGetSchema) {
285 std::unique_ptr<ExtensionAPI> apis( 334 std::unique_ptr<ExtensionAPI> apis(
286 ExtensionAPI::CreateWithDefaultConfiguration()); 335 ExtensionAPI::CreateWithDefaultConfiguration());
287 336
288 EXPECT_EQ(NULL, apis->GetSchema(std::string())); 337 EXPECT_EQ(NULL, apis->GetSchema(std::string()));
289 EXPECT_EQ(NULL, apis->GetSchema(std::string())); 338 EXPECT_EQ(NULL, apis->GetSchema(std::string()));
290 EXPECT_EQ(NULL, apis->GetSchema("experimental")); 339 EXPECT_EQ(NULL, apis->GetSchema("experimental"));
291 EXPECT_EQ(NULL, apis->GetSchema("experimental")); 340 EXPECT_EQ(NULL, apis->GetSchema("experimental"));
292 EXPECT_EQ(NULL, apis->GetSchema("foo")); 341 EXPECT_EQ(NULL, apis->GetSchema("foo"));
293 EXPECT_EQ(NULL, apis->GetSchema("foo")); 342 EXPECT_EQ(NULL, apis->GetSchema("foo"));
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 extension.get(), 888 extension.get(),
840 Feature::BLESSED_EXTENSION_CONTEXT, 889 Feature::BLESSED_EXTENSION_CONTEXT,
841 GURL()).is_available()); 890 GURL()).is_available());
842 EXPECT_FALSE(extension_api->IsAvailable("pageAction", 891 EXPECT_FALSE(extension_api->IsAvailable("pageAction",
843 extension.get(), 892 extension.get(),
844 Feature::BLESSED_EXTENSION_CONTEXT, 893 Feature::BLESSED_EXTENSION_CONTEXT,
845 GURL()).is_available()); 894 GURL()).is_available());
846 } 895 }
847 896
848 } // namespace extensions 897 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698