Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / browser / api / api_resource_manager_unittest.cc
blobd398b3075ec9ce60fe5f0b2a9c0ed23f38cd4945
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/files/file_path.h"
6 #include "base/strings/string_util.h"
7 #include "content/public/browser/browser_thread.h"
8 #include "extensions/browser/api/api_resource.h"
9 #include "extensions/browser/api/api_resource_manager.h"
10 #include "extensions/browser/api_unittest.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/test_util.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "url/gurl.h"
16 using content::BrowserThread;
18 namespace extensions {
20 class ApiResourceManagerUnitTest : public ApiUnitTest {};
22 class FakeApiResource : public ApiResource {
23 public:
24 explicit FakeApiResource(const std::string& owner_extension_id)
25 : ApiResource(owner_extension_id) {}
26 ~FakeApiResource() override {}
27 static const BrowserThread::ID kThreadId = BrowserThread::UI;
30 TEST_F(ApiResourceManagerUnitTest, TwoAppsCannotShareResources) {
31 scoped_ptr<ApiResourceManager<FakeApiResource>> manager(
32 new ApiResourceManager<FakeApiResource>(browser_context()));
33 scoped_refptr<extensions::Extension> extension_one =
34 test_util::CreateEmptyExtension("one");
35 scoped_refptr<extensions::Extension> extension_two =
36 test_util::CreateEmptyExtension("two");
38 const std::string extension_one_id(extension_one->id());
39 const std::string extension_two_id(extension_two->id());
41 int resource_one_id = manager->Add(new FakeApiResource(extension_one_id));
42 int resource_two_id = manager->Add(new FakeApiResource(extension_two_id));
43 CHECK(resource_one_id);
44 CHECK(resource_two_id);
46 // Confirm each extension can get its own resource.
47 ASSERT_TRUE(manager->Get(extension_one_id, resource_one_id) != NULL);
48 ASSERT_TRUE(manager->Get(extension_two_id, resource_two_id) != NULL);
50 // Confirm neither extension can get the other's resource.
51 ASSERT_TRUE(manager->Get(extension_one_id, resource_two_id) == NULL);
52 ASSERT_TRUE(manager->Get(extension_two_id, resource_one_id) == NULL);
54 // And make sure we're not susceptible to any Jedi mind tricks.
55 ASSERT_TRUE(manager->Get(std::string(), resource_one_id) == NULL);
58 } // namespace extensions