aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUjjwal Verma <ujjwalverma1111@gmail.com>2017-08-26 20:24:40 +0530
committerMaximilian Hils <git@maximilianhils.com>2017-09-03 21:02:29 +0200
commit8030f5003d83fd520c4267c117e1c60d83f6bef5 (patch)
treed7dae7104c8462211493e17ff57e61917a406392
parentb05bf588e68ba8be08e27ccdf40f97a59b17250a (diff)
downloadmitmproxy-8030f5003d83fd520c4267c117e1c60d83f6bef5.tar.gz
mitmproxy-8030f5003d83fd520c4267c117e1c60d83f6bef5.tar.bz2
mitmproxy-8030f5003d83fd520c4267c117e1c60d83f6bef5.zip
Added test
-rw-r--r--test/mitmproxy/contentviews/test_javascript.py24
-rw-r--r--test/mitmproxy/contentviews/test_js_data/simple-formatted.js136
-rw-r--r--test/mitmproxy/contentviews/test_js_data/simple.js2
3 files changed, 92 insertions, 70 deletions
diff --git a/test/mitmproxy/contentviews/test_javascript.py b/test/mitmproxy/contentviews/test_javascript.py
index 43039c93..23dd106e 100644
--- a/test/mitmproxy/contentviews/test_javascript.py
+++ b/test/mitmproxy/contentviews/test_javascript.py
@@ -1,10 +1,32 @@
+import pytest
+
from mitmproxy.contentviews import javascript
+from mitmproxy.test import tutils
from . import full_eval
+data = tutils.test_data.push("mitmproxy/contentviews/test_js_data/")
+
def test_view_javascript():
v = full_eval(javascript.ViewJavaScript())
assert v(b"[1, 2, 3]")
assert v(b"[1, 2, 3")
- assert v(b"function(a){[1, 2, 3]}")
+ assert v(b"function(a){[1, 2, 3]}") == ("JavaScript", [
+ [('text', 'function(a) {')],
+ [('text', ' [1, 2, 3]')],
+ [('text', '}')]
+ ])
assert v(b"\xfe") # invalid utf-8
+
+
+@pytest.mark.parametrize("filename", [
+ "simple.js",
+])
+def test_format_xml(filename):
+ path = data.path(filename)
+ with open(path) as f:
+ input = f.read()
+ with open("-formatted.".join(path.rsplit(".", 1))) as f:
+ expected = f.read()
+ js = javascript.beautify(input)
+ assert js == expected
diff --git a/test/mitmproxy/contentviews/test_js_data/simple-formatted.js b/test/mitmproxy/contentviews/test_js_data/simple-formatted.js
index 7ffd7b08..2b665f02 100644
--- a/test/mitmproxy/contentviews/test_js_data/simple-formatted.js
+++ b/test/mitmproxy/contentviews/test_js_data/simple-formatted.js
@@ -1,68 +1,68 @@
-/* _GlobalPrefix_ */
-this.gbar_=this.gbar_||{};
-(function(_) {
- var window=this;
-
-/* _Module_:sy25 */
- try {
- var Mn=function(){};
- _.y(Mn,Error);
- _.Nn=function() {
- this.b="pending";
- this.B=[];
- this.w=this.C=void 0
- };
- _.fe(_.Nn);
- var On=function() {
- _.qa.call(this,"Multiple attempts to set the state of this Result")
- };
- _.y(On,_.qa);
- _.Nn.prototype.ta=function() {
- return this.C
- };
- _.Pn=function(a,c,d) {
- "pending"==a.b?a.B.push( {
- hb:c,scope:d||null
- }
- ):c.call(d,a)
- };
- _.Nn.prototype.A=function(a) {
- if("pending"==this.b)this.C=a,this.b="success",Qn(this);
- else if(!Rn(this))throw new On;
- };
- _.Nn.prototype.o=function(a) {
- if("pending"==this.b)this.w=a,this.b="error",Qn(this);
- else if(!Rn(this))throw new On;
- };
- var Qn=function(a) {
- var c=a.B;
- a.B=[];
- for(var d=0;d<c.length;d++) {
- var e=c[d];
- e.hb.call(e.scope,a)
- }
-
- };
- _.Nn.prototype.cancel=function() {
- return"pending"==this.b?(this.o(new Mn),!0):!1
- };
- var Rn=function(a) {
- return"error"==a.b&&a.w instanceof Mn
- };
- _.Nn.prototype.then=function(a,c,d) {
- var e,f,g=new _.ie(function(a,c) {
- e=a;
- f=c
- }
- );
- _.Pn(this,function(a) {
- Rn(a)?g.cancel():"success"==a.b?e(a.ta()):"error"==a.b&&f(a.w)
- }
- );
- return g.then(a,c,d)
- };
-
- }
- catch(e) {
- _._DumpException(e)
- }
+/* _GlobalPrefix_ */
+this.gbar_=this.gbar_||{};
+(function(_) {
+ var window=this;
+
+/* _Module_:sy25 */
+ try {
+ var Mn=function(){};
+ _.y(Mn,Error);
+ _.Nn=function() {
+ this.b="pending";
+ this.B=[];
+ this.w=this.C=void 0
+ };
+ _.fe(_.Nn);
+ var On=function() {
+ _.qa.call(this,"Multiple attempts to set the state of this Result")
+ };
+ _.y(On,_.qa);
+ _.Nn.prototype.ta=function() {
+ return this.C
+ };
+ _.Pn=function(a,c,d) {
+ "pending"==a.b?a.B.push( {
+ hb:c,scope:d||null
+ }
+ ):c.call(d,a)
+ };
+ _.Nn.prototype.A=function(a) {
+ if("pending"==this.b)this.C=a,this.b="success",Qn(this);
+ else if(!Rn(this))throw new On;
+ };
+ _.Nn.prototype.o=function(a) {
+ if("pending"==this.b)this.w=a,this.b="error",Qn(this);
+ else if(!Rn(this))throw new On;
+ };
+ var Qn=function(a) {
+ var c=a.B;
+ a.B=[];
+ for(var d=0;d<c.length;d++) {
+ var e=c[d];
+ e.hb.call(e.scope,a)
+ }
+
+ };
+ _.Nn.prototype.cancel=function() {
+ return"pending"==this.b?(this.o(new Mn),!0):!1
+ };
+ var Rn=function(a) {
+ return"error"==a.b&&a.w instanceof Mn
+ };
+ _.Nn.prototype.then=function(a,c,d) {
+ var e,f,g=new _.ie(function(a,c) {
+ e=a;
+ f=c
+ }
+ );
+ _.Pn(this,function(a) {
+ Rn(a)?g.cancel():"success"==a.b?e(a.ta()):"error"==a.b&&f(a.w)
+ }
+ );
+ return g.then(a,c,d)
+ };
+
+ }
+ catch(e) {
+ _._DumpException(e)
+ }
diff --git a/test/mitmproxy/contentviews/test_js_data/simple.js b/test/mitmproxy/contentviews/test_js_data/simple.js
index 877dcf8d..66a56d8b 100644
--- a/test/mitmproxy/contentviews/test_js_data/simple.js
+++ b/test/mitmproxy/contentviews/test_js_data/simple.js
@@ -5,4 +5,4 @@ try{
var Mn=function(){};_.y(Mn,Error);_.Nn=function(){this.b="pending";this.B=[];this.w=this.C=void 0};_.fe(_.Nn);var On=function(){_.qa.call(this,"Multiple attempts to set the state of this Result")};_.y(On,_.qa);_.Nn.prototype.ta=function(){return this.C};_.Pn=function(a,c,d){"pending"==a.b?a.B.push({hb:c,scope:d||null}):c.call(d,a)};_.Nn.prototype.A=function(a){if("pending"==this.b)this.C=a,this.b="success",Qn(this);else if(!Rn(this))throw new On;};
_.Nn.prototype.o=function(a){if("pending"==this.b)this.w=a,this.b="error",Qn(this);else if(!Rn(this))throw new On;};var Qn=function(a){var c=a.B;a.B=[];for(var d=0;d<c.length;d++){var e=c[d];e.hb.call(e.scope,a)}};_.Nn.prototype.cancel=function(){return"pending"==this.b?(this.o(new Mn),!0):!1};var Rn=function(a){return"error"==a.b&&a.w instanceof Mn}; _.Nn.prototype.then=function(a,c,d){var e,f,g=new _.ie(function(a,c){e=a;f=c});_.Pn(this,function(a){Rn(a)?g.cancel():"success"==a.b?e(a.ta()):"error"==a.b&&f(a.w)});return g.then(a,c,d)};
-}catch(e){_._DumpException(e)} \ No newline at end of file
+}catch(e){_._DumpException(e)}