OLD | NEW |
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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "extensions/browser/api/device_permissions_prompt.h" | 7 #include "extensions/browser/api/device_permissions_prompt.h" |
8 #include "extensions/common/extension.h" | 8 #include "extensions/common/extension.h" |
9 #include "extensions/common/extension_builder.h" | 9 #include "extensions/common/extension_builder.h" |
10 #include "extensions/common/value_builder.h" | 10 #include "extensions/common/value_builder.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class DevicePermissionsPromptTest : public testing::Test {}; | 17 class DevicePermissionsPromptTest : public testing::Test {}; |
18 | 18 |
19 TEST_F(DevicePermissionsPromptTest, HidPromptMessages) { | 19 TEST_F(DevicePermissionsPromptTest, HidPromptMessages) { |
20 scoped_refptr<Extension> extension = | 20 scoped_refptr<Extension> extension = |
21 ExtensionBuilder() | 21 ExtensionBuilder() |
22 .SetManifest(std::move(DictionaryBuilder() | 22 .SetManifest(DictionaryBuilder() |
23 .Set("name", "Test Application") | 23 .Set("name", "Test Application") |
24 .Set("manifest_version", 2) | 24 .Set("manifest_version", 2) |
25 .Set("version", "1.0"))) | 25 .Set("version", "1.0") |
| 26 .Build()) |
26 .Build(); | 27 .Build(); |
27 | 28 |
28 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt = | 29 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt = |
29 DevicePermissionsPrompt::CreateHidPromptForTest(extension.get(), false); | 30 DevicePermissionsPrompt::CreateHidPromptForTest(extension.get(), false); |
30 EXPECT_EQ(base::ASCIIToUTF16("Select a HID device"), prompt->GetHeading()); | 31 EXPECT_EQ(base::ASCIIToUTF16("Select a HID device"), prompt->GetHeading()); |
31 EXPECT_EQ( | 32 EXPECT_EQ( |
32 base::ASCIIToUTF16( | 33 base::ASCIIToUTF16( |
33 "The application \"Test Application\" is requesting access to one of " | 34 "The application \"Test Application\" is requesting access to one of " |
34 "your devices."), | 35 "your devices."), |
35 prompt->GetPromptMessage()); | 36 prompt->GetPromptMessage()); |
36 | 37 |
37 prompt = | 38 prompt = |
38 DevicePermissionsPrompt::CreateHidPromptForTest(extension.get(), true); | 39 DevicePermissionsPrompt::CreateHidPromptForTest(extension.get(), true); |
39 EXPECT_EQ(base::ASCIIToUTF16("Select HID devices"), prompt->GetHeading()); | 40 EXPECT_EQ(base::ASCIIToUTF16("Select HID devices"), prompt->GetHeading()); |
40 EXPECT_EQ( | 41 EXPECT_EQ( |
41 base::ASCIIToUTF16( | 42 base::ASCIIToUTF16( |
42 "The application \"Test Application\" is requesting access to one or " | 43 "The application \"Test Application\" is requesting access to one or " |
43 "more of your devices."), | 44 "more of your devices."), |
44 prompt->GetPromptMessage()); | 45 prompt->GetPromptMessage()); |
45 } | 46 } |
46 | 47 |
47 TEST_F(DevicePermissionsPromptTest, UsbPromptMessages) { | 48 TEST_F(DevicePermissionsPromptTest, UsbPromptMessages) { |
48 scoped_refptr<Extension> extension = | 49 scoped_refptr<Extension> extension = |
49 ExtensionBuilder() | 50 ExtensionBuilder() |
50 .SetManifest(std::move(DictionaryBuilder() | 51 .SetManifest(DictionaryBuilder() |
51 .Set("name", "Test Application") | 52 .Set("name", "Test Application") |
52 .Set("manifest_version", 2) | 53 .Set("manifest_version", 2) |
53 .Set("version", "1.0"))) | 54 .Set("version", "1.0") |
| 55 .Build()) |
54 .Build(); | 56 .Build(); |
55 | 57 |
56 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt = | 58 scoped_refptr<DevicePermissionsPrompt::Prompt> prompt = |
57 DevicePermissionsPrompt::CreateUsbPromptForTest(extension.get(), false); | 59 DevicePermissionsPrompt::CreateUsbPromptForTest(extension.get(), false); |
58 EXPECT_EQ(base::ASCIIToUTF16("Select a USB device"), prompt->GetHeading()); | 60 EXPECT_EQ(base::ASCIIToUTF16("Select a USB device"), prompt->GetHeading()); |
59 EXPECT_EQ( | 61 EXPECT_EQ( |
60 base::ASCIIToUTF16( | 62 base::ASCIIToUTF16( |
61 "The application \"Test Application\" is requesting access to one of " | 63 "The application \"Test Application\" is requesting access to one of " |
62 "your devices."), | 64 "your devices."), |
63 prompt->GetPromptMessage()); | 65 prompt->GetPromptMessage()); |
64 | 66 |
65 prompt = | 67 prompt = |
66 DevicePermissionsPrompt::CreateUsbPromptForTest(extension.get(), true); | 68 DevicePermissionsPrompt::CreateUsbPromptForTest(extension.get(), true); |
67 EXPECT_EQ(base::ASCIIToUTF16("Select USB devices"), prompt->GetHeading()); | 69 EXPECT_EQ(base::ASCIIToUTF16("Select USB devices"), prompt->GetHeading()); |
68 EXPECT_EQ( | 70 EXPECT_EQ( |
69 base::ASCIIToUTF16( | 71 base::ASCIIToUTF16( |
70 "The application \"Test Application\" is requesting access to one or " | 72 "The application \"Test Application\" is requesting access to one or " |
71 "more of your devices."), | 73 "more of your devices."), |
72 prompt->GetPromptMessage()); | 74 prompt->GetPromptMessage()); |
73 } | 75 } |
74 | 76 |
75 } // namespace | 77 } // namespace |
76 | 78 |
77 } // namespace extensions | 79 } // namespace extensions |
OLD | NEW |