This source file includes following definitions.
- count
- HasMenuItem
- MenuItemCommandID
- MenuItemLabel
- ExecuteMenuItem
- HasBubbleView
- HasShownBubbleView
- ShowBubbleView
- GetBubbleView
- severity_
- GetSeverity
- HasMenuItem
- MenuItemCommandID
- MenuItemLabel
- ExecuteMenuItem
- TEST
- TEST
- TEST
- TEST
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/global_error/global_error.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class BaseError : public GlobalError {
public:
BaseError() { ++count_; }
virtual ~BaseError() { --count_; }
static int count() { return count_; }
virtual bool HasMenuItem() OVERRIDE { return false; }
virtual int MenuItemCommandID() OVERRIDE {
ADD_FAILURE();
return 0;
}
virtual base::string16 MenuItemLabel() OVERRIDE {
ADD_FAILURE();
return base::string16();
}
virtual void ExecuteMenuItem(Browser* browser) OVERRIDE { ADD_FAILURE(); }
virtual bool HasBubbleView() OVERRIDE { return false; }
virtual bool HasShownBubbleView() OVERRIDE { return false; }
virtual void ShowBubbleView(Browser* browser) OVERRIDE { ADD_FAILURE(); }
virtual GlobalErrorBubbleViewBase* GetBubbleView() OVERRIDE { return NULL; }
private:
static int count_;
DISALLOW_COPY_AND_ASSIGN(BaseError);
};
int BaseError::count_ = 0;
class MenuError : public BaseError {
public:
explicit MenuError(int command_id, Severity severity)
: command_id_(command_id),
severity_(severity) {
}
virtual Severity GetSeverity() OVERRIDE { return severity_; }
virtual bool HasMenuItem() OVERRIDE { return true; }
virtual int MenuItemCommandID() OVERRIDE { return command_id_; }
virtual base::string16 MenuItemLabel() OVERRIDE { return base::string16(); }
virtual void ExecuteMenuItem(Browser* browser) OVERRIDE {}
private:
int command_id_;
Severity severity_;
DISALLOW_COPY_AND_ASSIGN(MenuError);
};
}
TEST(GlobalErrorServiceTest, AddError) {
scoped_ptr<GlobalErrorService> service(new GlobalErrorService(NULL));
EXPECT_EQ(0u, service->errors().size());
BaseError* error1 = new BaseError;
service->AddGlobalError(error1);
EXPECT_EQ(1u, service->errors().size());
EXPECT_EQ(error1, service->errors()[0]);
BaseError* error2 = new BaseError;
service->AddGlobalError(error2);
EXPECT_EQ(2u, service->errors().size());
EXPECT_EQ(error1, service->errors()[0]);
EXPECT_EQ(error2, service->errors()[1]);
EXPECT_EQ(2, BaseError::count());
service.reset();
EXPECT_EQ(0, BaseError::count());
}
TEST(GlobalErrorServiceTest, RemoveError) {
scoped_ptr<GlobalErrorService> service(new GlobalErrorService(NULL));
BaseError error1;
service->AddGlobalError(&error1);
BaseError error2;
service->AddGlobalError(&error2);
EXPECT_EQ(2u, service->errors().size());
service->RemoveGlobalError(&error1);
EXPECT_EQ(1u, service->errors().size());
EXPECT_EQ(&error2, service->errors()[0]);
service->RemoveGlobalError(&error2);
EXPECT_EQ(0u, service->errors().size());
EXPECT_EQ(2, BaseError::count());
service.reset();
EXPECT_EQ(2, BaseError::count());
}
TEST(GlobalErrorServiceTest, GetMenuItem) {
MenuError* error1 = new MenuError(1, GlobalError::SEVERITY_LOW);
MenuError* error2 = new MenuError(2, GlobalError::SEVERITY_MEDIUM);
MenuError* error3 = new MenuError(3, GlobalError::SEVERITY_HIGH);
GlobalErrorService service(NULL);
service.AddGlobalError(error1);
service.AddGlobalError(error2);
service.AddGlobalError(error3);
EXPECT_EQ(error2, service.GetGlobalErrorByMenuItemCommandID(2));
EXPECT_EQ(error3, service.GetGlobalErrorByMenuItemCommandID(3));
EXPECT_EQ(NULL, service.GetGlobalErrorByMenuItemCommandID(4));
}
TEST(GlobalErrorServiceTest, HighestSeverity) {
MenuError* error1 = new MenuError(1, GlobalError::SEVERITY_LOW);
MenuError* error2 = new MenuError(2, GlobalError::SEVERITY_MEDIUM);
MenuError* error3 = new MenuError(3, GlobalError::SEVERITY_HIGH);
GlobalErrorService service(NULL);
EXPECT_EQ(NULL, service.GetHighestSeverityGlobalErrorWithWrenchMenuItem());
service.AddGlobalError(error1);
EXPECT_EQ(error1, service.GetHighestSeverityGlobalErrorWithWrenchMenuItem());
service.AddGlobalError(error2);
EXPECT_EQ(error2, service.GetHighestSeverityGlobalErrorWithWrenchMenuItem());
service.AddGlobalError(error3);
EXPECT_EQ(error3, service.GetHighestSeverityGlobalErrorWithWrenchMenuItem());
service.RemoveGlobalError(error3);
delete error3;
EXPECT_EQ(error2, service.GetHighestSeverityGlobalErrorWithWrenchMenuItem());
}