summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/reload_button_unittest.mm
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/cocoa/reload_button_unittest.mm')
-rw-r--r--chrome/browser/cocoa/reload_button_unittest.mm52
1 files changed, 50 insertions, 2 deletions
diff --git a/chrome/browser/cocoa/reload_button_unittest.mm b/chrome/browser/cocoa/reload_button_unittest.mm
index c2c9e84..19fde82 100644
--- a/chrome/browser/cocoa/reload_button_unittest.mm
+++ b/chrome/browser/cocoa/reload_button_unittest.mm
@@ -7,7 +7,7 @@
#import "chrome/browser/cocoa/reload_button.h"
#include "base/scoped_nsobject.h"
-#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/app/chrome_command_ids.h"
#import "chrome/browser/cocoa/cocoa_test_helper.h"
#import "chrome/browser/cocoa/test_event_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -109,7 +109,7 @@ TEST_F(ReloadButtonTest, SetIsLoadingForce) {
// Test that without force, stop mode is set immediately, but reload
// is affected by the hover status.
-TEST_F(ReloadButtonTest, SetIsLoadingNoForce) {
+TEST_F(ReloadButtonTest, SetIsLoadingNoForceUnHover) {
EXPECT_FALSE([button_ isMouseInside]);
EXPECT_EQ([button_ tag], IDC_RELOAD);
@@ -142,6 +142,54 @@ TEST_F(ReloadButtonTest, SetIsLoadingNoForce) {
EXPECT_EQ([button_ tag], IDC_RELOAD);
}
+// Test that without force, stop mode is set immediately, and reload
+// will be set after a timeout.
+// TODO(shess): Reenable, http://crbug.com/61485
+TEST_F(ReloadButtonTest, DISABLED_SetIsLoadingNoForceTimeout) {
+ // When the event loop first spins, some delayed tracking-area setup
+ // is done, which causes -mouseExited: to be called. Spin it at
+ // least once, and dequeue any pending events.
+ // TODO(shess): It would be more reasonable to have an MockNSTimer
+ // factory for the class to use, which this code could fire
+ // directly.
+ while ([NSApp nextEventMatchingMask:NSAnyEventMask
+ untilDate:nil
+ inMode:NSDefaultRunLoopMode
+ dequeue:YES]) {
+ }
+
+ const NSTimeInterval kShortTimeout = 0.1;
+ [ReloadButton setPendingReloadTimeout:kShortTimeout];
+
+ EXPECT_FALSE([button_ isMouseInside]);
+ EXPECT_EQ(IDC_RELOAD, [button_ tag]);
+
+ // Move the mouse into the button and press it.
+ [button_ mouseEntered:nil];
+ EXPECT_TRUE([button_ isMouseInside]);
+ [button_ setIsLoading:YES force:NO];
+ EXPECT_EQ(IDC_STOP, [button_ tag]);
+
+ // Does not change to reload immediately when the mouse is hovered.
+ EXPECT_TRUE([button_ isMouseInside]);
+ [button_ setIsLoading:NO force:NO];
+ EXPECT_TRUE([button_ isMouseInside]);
+ EXPECT_EQ(IDC_STOP, [button_ tag]);
+ EXPECT_TRUE([button_ isMouseInside]);
+
+ // Spin event loop until the timeout passes.
+ NSDate* pastTimeout = [NSDate dateWithTimeIntervalSinceNow:2 * kShortTimeout];
+ [NSApp nextEventMatchingMask:NSAnyEventMask
+ untilDate:pastTimeout
+ inMode:NSDefaultRunLoopMode
+ dequeue:NO];
+
+ // Mouse is still hovered, button is in reload mode. If the mouse
+ // is no longer hovered, see comment at top of function.
+ EXPECT_TRUE([button_ isMouseInside]);
+ EXPECT_EQ(IDC_RELOAD, [button_ tag]);
+}
+
// Test that pressing stop after reload mode has been requested
// doesn't forward the stop message.
TEST_F(ReloadButtonTest, StopAfterReloadSet) {