This source file includes following definitions.
- SetUp
- TearDown
- correct_extension
- incorrect_extension
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/chromeos/ui/idle_app_name_notification_view.h"
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "extensions/common/manifest_constants.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
const char kTestAppName[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
}
class IdleAppNameNotificationViewTest : public BrowserWithTestWindowTest {
public:
IdleAppNameNotificationViewTest()
: BrowserWithTestWindowTest(
Browser::TYPE_TABBED,
chrome::HOST_DESKTOP_TYPE_ASH,
false) {
}
virtual ~IdleAppNameNotificationViewTest() {
}
virtual void SetUp() OVERRIDE {
CommandLine::ForCurrentProcess()->AppendSwitchASCII(::switches::kAppId,
kTestAppName);
BrowserWithTestWindowTest::SetUp();
base::DictionaryValue manifest;
manifest.SetString(extensions::manifest_keys::kName, "Test");
manifest.SetString(extensions::manifest_keys::kVersion, "1");
manifest.SetString(extensions::manifest_keys::kDescription, "Test app");
manifest.SetString("author.email", "Someone");
std::string error;
correct_extension_ =
extensions::Extension::Create(base::FilePath(),
extensions::Manifest::UNPACKED,
manifest,
extensions::Extension::NO_FLAGS,
kTestAppName,
&error);
base::DictionaryValue manifest2;
manifest2.SetString(extensions::manifest_keys::kName, "Test");
manifest2.SetString(extensions::manifest_keys::kVersion, "1");
manifest2.SetString(extensions::manifest_keys::kDescription, "Test app");
incorrect_extension_ =
extensions::Extension::Create(base::FilePath(),
extensions::Manifest::UNPACKED,
manifest2,
extensions::Extension::NO_FLAGS,
kTestAppName,
&error);
}
virtual void TearDown() OVERRIDE {
base::MessageLoop::current()->RunUntilIdle();
BrowserWithTestWindowTest::TearDown();
}
extensions::Extension* correct_extension() { return correct_extension_; }
extensions::Extension* incorrect_extension() { return incorrect_extension_; }
private:
scoped_refptr<extensions::Extension> correct_extension_;
scoped_refptr<extensions::Extension> incorrect_extension_;
DISALLOW_COPY_AND_ASSIGN(IdleAppNameNotificationViewTest);
};
TEST_F(IdleAppNameNotificationViewTest, CheckTooEarlyDestruction) {
scoped_ptr<chromeos::IdleAppNameNotificationView> message(
new chromeos::IdleAppNameNotificationView(10, 5, correct_extension()));
}
TEST_F(IdleAppNameNotificationViewTest, CheckSelfDestruction) {
scoped_ptr<chromeos::IdleAppNameNotificationView> message(
new chromeos::IdleAppNameNotificationView(10, 5, correct_extension()));
EXPECT_TRUE(message->IsVisible());
for (int i = 0; i < 50 && message->IsVisible(); i++) {
sleep(1);
base::MessageLoop::current()->RunUntilIdle();
}
EXPECT_FALSE(message->IsVisible());
}
TEST_F(IdleAppNameNotificationViewTest, CheckCorrectApp) {
scoped_ptr<chromeos::IdleAppNameNotificationView> message(
new chromeos::IdleAppNameNotificationView(10, 5, correct_extension()));
base::string16 text = message->GetShownTextForTest();
base::string16 name = base::ASCIIToUTF16("Test");
EXPECT_EQ(name, text.substr(0, name.length()));
}
TEST_F(IdleAppNameNotificationViewTest, CheckInvalidApp) {
scoped_ptr<chromeos::IdleAppNameNotificationView> message(
new chromeos::IdleAppNameNotificationView(10, 5, NULL));
base::string16 text = message->GetShownTextForTest();
base::string16 error = l10n_util::GetStringUTF16(
IDS_IDLE_APP_NAME_UNKNOWN_APPLICATION_NOTIFICATION);
EXPECT_EQ(error, text);
}