From 01203a8b1bf6d50da350ddaaabc578251a31ef36 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Fri, 15 May 2015 15:31:03 +0800 Subject: [PATCH 1/2] Increase the VideoPlayer and webview tests --- tests/js-tests/project.json | 2 + tests/js-tests/src/GUITest/UISceneManager.js | 38 ++++++++-- .../UIVideoPlayerTest/UIVideoPlayerTest.js | 73 +++++++++++++++++++ .../GUITest/UIWebViewTest/UIWebViewTest.js | 70 ++++++++++++++++++ .../src/GUITest/UIWebViewTest/weview.html | 21 ++++++ .../src/GUITest/UIWebViewTest/weview2.html | 21 ++++++ 6 files changed, 217 insertions(+), 8 deletions(-) create mode 100644 tests/js-tests/src/GUITest/UIVideoPlayerTest/UIVideoPlayerTest.js create mode 100644 tests/js-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js create mode 100644 tests/js-tests/src/GUITest/UIWebViewTest/weview.html create mode 100644 tests/js-tests/src/GUITest/UIWebViewTest/weview2.html diff --git a/tests/js-tests/project.json b/tests/js-tests/project.json index e081ed9bdc..f525f7b3f0 100644 --- a/tests/js-tests/project.json +++ b/tests/js-tests/project.json @@ -168,6 +168,8 @@ "src/GUITest/UITextFieldTest/UITextFieldTest.js", "src/GUITest/UIRichTextTest/UIRichTextTest.js", "src/GUITest/UITextTest/UITextTest.js", + "src/GUITest/UIVideoPlayerTest/UIVideoPlayerTest.js", + "src/GUITest/UIWebViewTest/UIWebViewTest.js", "src/CocoStudioTest/SceneTest/TriggerCode/Acts.js", "src/CocoStudioTest/SceneTest/TriggerCode/Cons.js", diff --git a/tests/js-tests/src/GUITest/UISceneManager.js b/tests/js-tests/src/GUITest/UISceneManager.js index 61105998dc..6275cc61a9 100644 --- a/tests/js-tests/src/GUITest/UISceneManager.js +++ b/tests/js-tests/src/GUITest/UISceneManager.js @@ -528,21 +528,40 @@ return new UIRichTextTest(); } } + ], + "UIVideoPlayer": [ + { + title: "UIVideoPlayerTest", + func: function () { + return new UIVideoPlayerTest(); + } + } + ], + "UIWebViewTest": [ + { + title: "UIWebViewTest", + func: function () { + return new UIWebViewTest(); + } + } ] }; + var guiTestScene = null; global.GUITestScene = cc.Class.extend({ runThisTest: function(){ - cc.director.runScene(new listScene); + if(guiTestScene === null) + guiTestScene = new listScene; + cc.director.runScene(guiTestScene); } }); var listScene = TestScene.extend({ - onEnter: function(){ - TestScene.prototype.onEnter.call(this); + ctor: function(){ + TestScene.prototype.ctor.call(this); var menu = new cc.Menu(); menu.x = 0; @@ -567,6 +586,14 @@ this._menu = menu; this.addChild(menu); + this._length = 0; + for(var p in testingItems){ + this._length++; + } + }, + + onEnter: function(){ + TestScene.prototype.onEnter.call(this); if ('touches' in cc.sys.capabilities) cc.eventManager.addListener({ event: cc.EventListener.TOUCH_ALL_AT_ONCE, @@ -591,11 +618,6 @@ } }, this); } - - this._length = 0; - for(var p in testingItems){ - this._length++; - } }, moveMenu: function(delta){ diff --git a/tests/js-tests/src/GUITest/UIVideoPlayerTest/UIVideoPlayerTest.js b/tests/js-tests/src/GUITest/UIVideoPlayerTest/UIVideoPlayerTest.js new file mode 100644 index 0000000000..f8cb3fa01e --- /dev/null +++ b/tests/js-tests/src/GUITest/UIVideoPlayerTest/UIVideoPlayerTest.js @@ -0,0 +1,73 @@ +var UIVideoPlayerTest = UIScene.extend({ + + onEnter: function(){ + UIScene.prototype.onEnter.call(this); + + var video = new ccui.VideoPlayer("res/cocosui/UITest/movie.mp4"); + video.setContentSize(320, 240); + video.setPosition(800/2, 450/2); + video.setScale(0.5); + window.video = video; + this.addChild(video); + + var list = [ + { name: "PLAY", func: function(){ + cc.log("play!"); + video.play(); + }}, + { name: "STOP", func: function(){ + cc.log("stop!"); + video.stop(); + }}, + { name: "PAUSE", func: function(){ + cc.log("pause!"); + video.pause(); + }}, + { name: "RESUME", func: function(){ + cc.log("resume!"); + video.resume(); + }}, + { name: "SEEKTO", func: function(){ + var sec = ((Math.random() * 3) * 100 | 0) / 100; + cc.log("seekTo %f sec!", sec); + video.seekTo(sec); + }}, + { name: "ISPLAYING", func: function(){ + cc.log("isPlaying!"); + cc.log(video.isPlaying()); + }}, + { name: "Full Screen", func: function(){ + cc.log("setFullScreenEnabled!"); + video.setFullScreenEnabled(); + }}, + { name: "Scale", func: function(){ + var scale = ((Math.random() * 0.5 + 0.2) * 100 | 0) / 100; + cc.log("setScale(%f)!", scale); + video.setScale(scale); + }}, + { name: "AnchorPoint 0 / 1", func: function(){ + var anp = video.getAnchorPoint(); + if(anp.x === 1) + video.setAnchorPoint(0, 0); + else + video.setAnchorPoint(1, 1); + }}, + { name: "AnchorPoint 0.5", func: function(){ + video.setAnchorPoint(0.5, 0.5); + }} + ]; + + var layer = this; + list.forEach(function(item, i){ + var but = new ccui.Button(); + but.setPosition( 140 + (i / 5 | 0) * 500, 300 - (i % 5) * 35); + but.setTitleText(item.name); + but.setZoomScale(0.3); + but.setPressedActionEnabled(true); + but.addClickEventListener(item.func); + layer.addChild(but); + }); + + } + +}); \ No newline at end of file diff --git a/tests/js-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js b/tests/js-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js new file mode 100644 index 0000000000..0797cb793e --- /dev/null +++ b/tests/js-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js @@ -0,0 +1,70 @@ +var UIWebViewTest = UIScene.extend({ + + onEnter: function(){ + UIScene.prototype.onEnter.call(this); + + var webView = new ccui.WebView("src/GUITest/UIWebViewTest/weview.html"); + webView.setContentSize(320, 240); + webView.setPosition(800/2, 450/2); + webView.setScale(0.5); + window.webView = webView; + this.addChild(webView); + + var cb = function(){ + cc.log("loaded"); + }; + webView.addEventListener("load", cb); + + var list = [ + { name: "loadURL", func: function(){ + cc.log("loadURL!"); + webView.loadURL("src/GUITest/UIWebViewTest/weview2.html"); + }}, + { name: "reload", func: function(){ + cc.log("reload!"); + webView.reload(); + }}, + { name: "goBack", func: function(){ + cc.log("goBack!"); + webView.goBack(); + }}, + { name: "goForward", func: function(){ + cc.log("goForward!"); + webView.goForward(); + }}, + { name: "evaluateJS", func: function(){ + cc.log("evaluateJS!"); + var code = "document.getElementById('test').innerHTML = 'evaluateJS!'"; + webView.evaluateJS(code); + }}, + { name: "Scale", func: function(){ + var scale = ((Math.random() * 0.5 + 0.2) * 100 | 0) / 100; + cc.log("setScale(%f)!", scale); + webView.setScale(scale); + }}, + { name: "AnchorPoint 0 / 1", func: function(){ + var anp = webView.getAnchorPoint(); + if(anp.x === 1) + webView.setAnchorPoint(0, 0); + else + webView.setAnchorPoint(1, 1); + }}, + { name: "AnchorPoint 0.5", func: function(){ + webView.setAnchorPoint(0.5, 0.5); + }} + ]; + + var layer = this; + list.forEach(function(item, i){ + var but = new ccui.Button(); + but.setPosition( 140 + (i / 5 | 0) * 500, 300 - (i % 5) * 35); + but.setTitleText(item.name); + but.setZoomScale(0.3); + but.setPressedActionEnabled(true); + but.addClickEventListener(item.func); + layer.addChild(but); + }); + + } + +}); \ No newline at end of file diff --git a/tests/js-tests/src/GUITest/UIWebViewTest/weview.html b/tests/js-tests/src/GUITest/UIWebViewTest/weview.html new file mode 100644 index 0000000000..99db398e49 --- /dev/null +++ b/tests/js-tests/src/GUITest/UIWebViewTest/weview.html @@ -0,0 +1,21 @@ + + + + + Test1 + + + +
+ Page 1 +
+
+ goto page2 +
+
+ + \ No newline at end of file diff --git a/tests/js-tests/src/GUITest/UIWebViewTest/weview2.html b/tests/js-tests/src/GUITest/UIWebViewTest/weview2.html new file mode 100644 index 0000000000..28602b3fa7 --- /dev/null +++ b/tests/js-tests/src/GUITest/UIWebViewTest/weview2.html @@ -0,0 +1,21 @@ + + + + + + + + +
+ Page 2 +
+
+ goto page1 +
+
+ + \ No newline at end of file From 376a3f28665af73fa604543c25f6be80be92e775 Mon Sep 17 00:00:00 2001 From: VisualSJ Date: Fri, 15 May 2015 15:45:37 +0800 Subject: [PATCH 2/2] [ci skip]Fix naming errors --- tests/js-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js | 4 ++-- .../src/GUITest/UIWebViewTest/{weview.html => webview.html} | 2 +- .../src/GUITest/UIWebViewTest/{weview2.html => webview2.html} | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename tests/js-tests/src/GUITest/UIWebViewTest/{weview.html => webview.html} (87%) rename tests/js-tests/src/GUITest/UIWebViewTest/{weview2.html => webview2.html} (87%) diff --git a/tests/js-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js b/tests/js-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js index 0797cb793e..661f83dff0 100644 --- a/tests/js-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js +++ b/tests/js-tests/src/GUITest/UIWebViewTest/UIWebViewTest.js @@ -3,7 +3,7 @@ var UIWebViewTest = UIScene.extend({ onEnter: function(){ UIScene.prototype.onEnter.call(this); - var webView = new ccui.WebView("src/GUITest/UIWebViewTest/weview.html"); + var webView = new ccui.WebView("src/GUITest/UIWebViewTest/webview.html"); webView.setContentSize(320, 240); webView.setPosition(800/2, 450/2); webView.setScale(0.5); @@ -18,7 +18,7 @@ var UIWebViewTest = UIScene.extend({ var list = [ { name: "loadURL", func: function(){ cc.log("loadURL!"); - webView.loadURL("src/GUITest/UIWebViewTest/weview2.html"); + webView.loadURL("src/GUITest/UIWebViewTest/webview2.html"); }}, { name: "reload", func: function(){ cc.log("reload!"); diff --git a/tests/js-tests/src/GUITest/UIWebViewTest/weview.html b/tests/js-tests/src/GUITest/UIWebViewTest/webview.html similarity index 87% rename from tests/js-tests/src/GUITest/UIWebViewTest/weview.html rename to tests/js-tests/src/GUITest/UIWebViewTest/webview.html index 99db398e49..42154f74fb 100644 --- a/tests/js-tests/src/GUITest/UIWebViewTest/weview.html +++ b/tests/js-tests/src/GUITest/UIWebViewTest/webview.html @@ -14,7 +14,7 @@ Page 1
- goto page2 + goto page2
diff --git a/tests/js-tests/src/GUITest/UIWebViewTest/weview2.html b/tests/js-tests/src/GUITest/UIWebViewTest/webview2.html similarity index 87% rename from tests/js-tests/src/GUITest/UIWebViewTest/weview2.html rename to tests/js-tests/src/GUITest/UIWebViewTest/webview2.html index 28602b3fa7..24fcc44684 100644 --- a/tests/js-tests/src/GUITest/UIWebViewTest/weview2.html +++ b/tests/js-tests/src/GUITest/UIWebViewTest/webview2.html @@ -14,7 +14,7 @@ Page 2
- goto page1 + goto page1