1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef XWALK_APPLICATION_TEST_APPLICATION_TESTAPI_H_
6 #define XWALK_APPLICATION_TEST_APPLICATION_TESTAPI_H_
10 #include "xwalk/extensions/browser/xwalk_extension_function_handler.h"
11 #include "xwalk/extensions/common/xwalk_extension.h"
13 using xwalk::extensions::XWalkExtension;
14 using xwalk::extensions::XWalkExtensionFunctionHandler;
15 using xwalk::extensions::XWalkExtensionFunctionInfo;
16 using xwalk::extensions::XWalkExtensionInstance;
19 class MessageLoopRunner;
22 class ApiTestExtensionInstance : public XWalkExtensionInstance {
24 // Observer will be created in UI thread.
27 virtual void OnTestNotificationReceived(
28 scoped_ptr<XWalkExtensionFunctionInfo> info,
29 const std::string& result_str) = 0;
31 virtual ~Observer() {}
34 explicit ApiTestExtensionInstance(Observer* observer = NULL);
36 virtual void HandleMessage(scoped_ptr<base::Value> msg) OVERRIDE;
39 void OnNotifyPass(scoped_ptr<XWalkExtensionFunctionInfo> info);
40 void OnNotifyFail(scoped_ptr<XWalkExtensionFunctionInfo> info);
41 void OnNotifyTimeout(scoped_ptr<XWalkExtensionFunctionInfo> info);
44 XWalkExtensionFunctionHandler handler_;
47 class ApiTestExtension : public XWalkExtension {
51 virtual XWalkExtensionInstance* CreateInstance() OVERRIDE;
53 void SetObserver(ApiTestExtensionInstance::Observer* observer);
56 ApiTestExtensionInstance::Observer* observer_;
59 class ApiTestRunner : public ApiTestExtensionInstance::Observer {
69 virtual ~ApiTestRunner();
71 // Block wait until the test API is called. If the test API is already called,
72 // this will return immediately. Returns true if the waiting happened, returns
73 // false if the waiting does not happen.
74 bool WaitForTestNotification();
76 // Implement ApiTestExtensionInstance::Observer.
77 virtual void OnTestNotificationReceived(
78 scoped_ptr<XWalkExtensionFunctionInfo> info,
79 const std::string& result_str) OVERRIDE;
81 void PostResultToNotificationCallback();
83 Result GetTestsResult() const;
86 // Reset current test result, then it can wait again.
89 scoped_ptr<XWalkExtensionFunctionInfo> notify_func_info_;
91 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
94 #endif // XWALK_APPLICATION_TEST_APPLICATION_TESTAPI_H_