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

Side by Side Diff: chrome/browser/extensions/api/api_resource_manager_unittest.cc

Issue 319543006: Move c/b/e/api/api_resource_manager_unittest.cc to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use TestBrowserThreadBundle instead Created 6 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/web_request/web_request_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/files/file_path.h"
6 #include "base/strings/string_util.h"
7 #include "chrome/browser/extensions/extension_function_test_utils.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/extensions/extension_test_util.h"
10 #include "chrome/test/base/browser_with_test_window_test.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "extensions/browser/api/api_resource.h"
13 #include "extensions/browser/api/api_resource_manager.h"
14 #include "extensions/common/extension.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h"
17
18 namespace utils = extension_function_test_utils;
19
20 using content::BrowserThread;
21
22 namespace extensions {
23
24 // TODO(rockot): Move these tests to src/extensions.
25 class ApiResourceManagerUnitTest : public BrowserWithTestWindowTest {
26 public:
27 virtual void SetUp() { BrowserWithTestWindowTest::SetUp(); }
28 };
29
30 class FakeApiResource : public ApiResource {
31 public:
32 explicit FakeApiResource(const std::string& owner_extension_id)
33 : ApiResource(owner_extension_id) {}
34 virtual ~FakeApiResource() {}
35 static const BrowserThread::ID kThreadId = BrowserThread::UI;
36 };
37
38 TEST_F(ApiResourceManagerUnitTest, TwoAppsCannotShareResources) {
39 scoped_ptr<ApiResourceManager<FakeApiResource> > manager(
40 new ApiResourceManager<FakeApiResource>(NULL));
41 scoped_refptr<extensions::Extension> extension_one(
42 utils::CreateEmptyExtension("one"));
43 scoped_refptr<extensions::Extension> extension_two(
44 utils::CreateEmptyExtension("two"));
45
46 const std::string extension_one_id(extension_one->id());
47 const std::string extension_two_id(extension_two->id());
48
49 int resource_one_id = manager->Add(new FakeApiResource(extension_one_id));
50 int resource_two_id = manager->Add(new FakeApiResource(extension_two_id));
51 CHECK(resource_one_id);
52 CHECK(resource_two_id);
53
54 // Confirm each extension can get its own resource.
55 ASSERT_TRUE(manager->Get(extension_one_id, resource_one_id) != NULL);
56 ASSERT_TRUE(manager->Get(extension_two_id, resource_two_id) != NULL);
57
58 // Confirm neither extension can get the other's resource.
59 ASSERT_TRUE(manager->Get(extension_one_id, resource_two_id) == NULL);
60 ASSERT_TRUE(manager->Get(extension_two_id, resource_one_id) == NULL);
61
62 // And make sure we're not susceptible to any Jedi mind tricks.
63 ASSERT_TRUE(manager->Get(std::string(), resource_one_id) == NULL);
64 }
65
66 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/web_request/web_request_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698