OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/ui/idle_app_name_notification_view.h" | 5 #include "chrome/browser/chromeos/ui/idle_app_name_notification_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 scoped_refptr<extensions::Extension> correct_extension_; | 79 scoped_refptr<extensions::Extension> correct_extension_; |
80 scoped_refptr<extensions::Extension> incorrect_extension_; | 80 scoped_refptr<extensions::Extension> incorrect_extension_; |
81 | 81 |
82 DISALLOW_COPY_AND_ASSIGN(IdleAppNameNotificationViewTest); | 82 DISALLOW_COPY_AND_ASSIGN(IdleAppNameNotificationViewTest); |
83 }; | 83 }; |
84 | 84 |
85 // Check that creating and immediate destroying does not crash (and closes the | 85 // Check that creating and immediate destroying does not crash (and closes the |
86 // message). | 86 // message). |
87 TEST_F(IdleAppNameNotificationViewTest, CheckTooEarlyDestruction) { | 87 TEST_F(IdleAppNameNotificationViewTest, CheckTooEarlyDestruction) { |
88 // Create a message which is visible for 10ms and fades in/out for 5ms. | 88 // Create a message which is visible for 10ms and fades in/out for 5ms. |
89 scoped_ptr<chromeos::IdleAppNameNotificationView> message( | 89 std::unique_ptr<chromeos::IdleAppNameNotificationView> message( |
90 new chromeos::IdleAppNameNotificationView(10, 5, correct_extension())); | 90 new chromeos::IdleAppNameNotificationView(10, 5, correct_extension())); |
91 } | 91 } |
92 | 92 |
93 // Check that the message gets created and it destroys itself after time. | 93 // Check that the message gets created and it destroys itself after time. |
94 TEST_F(IdleAppNameNotificationViewTest, CheckSelfDestruction) { | 94 TEST_F(IdleAppNameNotificationViewTest, CheckSelfDestruction) { |
95 // Create a message which is visible for 10ms and fades in/out for 5ms. | 95 // Create a message which is visible for 10ms and fades in/out for 5ms. |
96 scoped_ptr<chromeos::IdleAppNameNotificationView> message( | 96 std::unique_ptr<chromeos::IdleAppNameNotificationView> message( |
97 new chromeos::IdleAppNameNotificationView(10, 5, correct_extension())); | 97 new chromeos::IdleAppNameNotificationView(10, 5, correct_extension())); |
98 EXPECT_TRUE(message->IsVisible()); | 98 EXPECT_TRUE(message->IsVisible()); |
99 | 99 |
100 // Wait now for some time and see that it closes itself again. | 100 // Wait now for some time and see that it closes itself again. |
101 for (int i = 0; i < 50 && message->IsVisible(); i++) { | 101 for (int i = 0; i < 50 && message->IsVisible(); i++) { |
102 sleep(1); | 102 sleep(1); |
103 base::MessageLoop::current()->RunUntilIdle(); | 103 base::MessageLoop::current()->RunUntilIdle(); |
104 } | 104 } |
105 EXPECT_FALSE(message->IsVisible()); | 105 EXPECT_FALSE(message->IsVisible()); |
106 } | 106 } |
107 | 107 |
108 // Check that the shown text for a correct application is correct. | 108 // Check that the shown text for a correct application is correct. |
109 TEST_F(IdleAppNameNotificationViewTest, CheckCorrectApp) { | 109 TEST_F(IdleAppNameNotificationViewTest, CheckCorrectApp) { |
110 // Create a message which is visible for 10ms and fades in/out for 5ms. | 110 // Create a message which is visible for 10ms and fades in/out for 5ms. |
111 scoped_ptr<chromeos::IdleAppNameNotificationView> message( | 111 std::unique_ptr<chromeos::IdleAppNameNotificationView> message( |
112 new chromeos::IdleAppNameNotificationView(10, 5, correct_extension())); | 112 new chromeos::IdleAppNameNotificationView(10, 5, correct_extension())); |
113 base::string16 text = message->GetShownTextForTest(); | 113 base::string16 text = message->GetShownTextForTest(); |
114 // Check that the string is the application name. | 114 // Check that the string is the application name. |
115 base::string16 name = base::ASCIIToUTF16("Test"); | 115 base::string16 name = base::ASCIIToUTF16("Test"); |
116 EXPECT_EQ(name, text.substr(0, name.length())); | 116 EXPECT_EQ(name, text.substr(0, name.length())); |
117 } | 117 } |
118 | 118 |
119 // Check that an invalid app gets shown accordingly. | 119 // Check that an invalid app gets shown accordingly. |
120 TEST_F(IdleAppNameNotificationViewTest, CheckInvalidApp) { | 120 TEST_F(IdleAppNameNotificationViewTest, CheckInvalidApp) { |
121 // Create a message which is visible for 10ms and fades in/out for 5ms. | 121 // Create a message which is visible for 10ms and fades in/out for 5ms. |
122 scoped_ptr<chromeos::IdleAppNameNotificationView> message( | 122 std::unique_ptr<chromeos::IdleAppNameNotificationView> message( |
123 new chromeos::IdleAppNameNotificationView(10, 5, NULL)); | 123 new chromeos::IdleAppNameNotificationView(10, 5, NULL)); |
124 base::string16 text = message->GetShownTextForTest(); | 124 base::string16 text = message->GetShownTextForTest(); |
125 base::string16 error = l10n_util::GetStringUTF16( | 125 base::string16 error = l10n_util::GetStringUTF16( |
126 IDS_IDLE_APP_NAME_UNKNOWN_APPLICATION_NOTIFICATION); | 126 IDS_IDLE_APP_NAME_UNKNOWN_APPLICATION_NOTIFICATION); |
127 EXPECT_EQ(error, text); | 127 EXPECT_EQ(error, text); |
128 } | 128 } |
OLD | NEW |