Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: extensions/browser/api/alarms/alarms_api_unittest.cc

Issue 2818533003: Make nesting/running states a RunLoop rather than a MessageLoop concept. (Closed)
Patch Set: still need to check MessageLoop::current() in Mojo's RunLoopNestingObserver::GetForThread() Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file tests the chrome.alarms extension API. 5 // This file tests the chrome.alarms extension API.
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "base/test/simple_test_clock.h" 12 #include "base/test/simple_test_clock.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "content/public/test/mock_render_process_host.h" 15 #include "content/public/test/mock_render_process_host.h"
15 #include "extensions/browser/api/alarms/alarm_manager.h" 16 #include "extensions/browser/api/alarms/alarm_manager.h"
16 #include "extensions/browser/api/alarms/alarms_api.h" 17 #include "extensions/browser/api/alarms/alarms_api.h"
17 #include "extensions/browser/api/alarms/alarms_api_constants.h" 18 #include "extensions/browser/api/alarms/alarms_api_constants.h"
18 #include "extensions/browser/api_test_utils.h" 19 #include "extensions/browser/api_test_utils.h"
19 #include "extensions/browser/api_unittest.h" 20 #include "extensions/browser/api_unittest.h"
20 #include "extensions/common/extension_messages.h" 21 #include "extensions/common/extension_messages.h"
21 #include "ipc/ipc_test_sink.h" 22 #include "ipc/ipc_test_sink.h"
22 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 25
25 typedef extensions::api::alarms::Alarm JsAlarm; 26 typedef extensions::api::alarms::Alarm JsAlarm;
26 27
27 namespace extensions { 28 namespace extensions {
28 29
29 namespace utils = api_test_utils; 30 namespace utils = api_test_utils;
30 31
31 namespace { 32 namespace {
32 33
33 // Test delegate which quits the message loop when an alarm fires. 34 // Test delegate which quits the message loop when an alarm fires.
34 class AlarmDelegate : public AlarmManager::Delegate { 35 class AlarmDelegate : public AlarmManager::Delegate {
35 public: 36 public:
36 ~AlarmDelegate() override {} 37 ~AlarmDelegate() override {}
37 void OnAlarm(const std::string& extension_id, const Alarm& alarm) override { 38 void OnAlarm(const std::string& extension_id, const Alarm& alarm) override {
38 alarms_seen.push_back(alarm.js_alarm->name); 39 alarms_seen.push_back(alarm.js_alarm->name);
39 if (base::MessageLoop::current()->is_running()) 40 if (base::RunLoop::IsRunningOnCurrentThread())
40 base::MessageLoop::current()->QuitWhenIdle(); 41 base::MessageLoop::current()->QuitWhenIdle();
41 } 42 }
42 43
43 std::vector<std::string> alarms_seen; 44 std::vector<std::string> alarms_seen;
44 }; 45 };
45 46
46 } // namespace 47 } // namespace
47 48
48 void RunScheduleNextPoll(AlarmManager* alarm_manager) { 49 void RunScheduleNextPoll(AlarmManager* alarm_manager) {
49 alarm_manager->ScheduleNextPoll(); 50 alarm_manager->ScheduleNextPoll();
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 755
755 // The next poll should be the first poll that hasn't happened and is in-line 756 // The next poll should be the first poll that hasn't happened and is in-line
756 // with the original scheduling. 757 // with the original scheduling.
757 // Last poll was at 380 seconds; next poll should be at 480 seconds. 758 // Last poll was at 380 seconds; next poll should be at 480 seconds.
758 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ + 759 EXPECT_DOUBLE_EQ((alarm_manager_->last_poll_time_ +
759 base::TimeDelta::FromSeconds(100)).ToJsTime(), 760 base::TimeDelta::FromSeconds(100)).ToJsTime(),
760 alarm_manager_->next_poll_time_.ToJsTime()); 761 alarm_manager_->next_poll_time_.ToJsTime());
761 } 762 }
762 763
763 } // namespace extensions 764 } // namespace extensions
OLDNEW
« no previous file with comments | « device/bluetooth/test/test_bluetooth_adapter_observer.cc ('k') | mash/quick_launch/quick_launch.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698