Esempio n. 1
0
		public IEnumerable<GeckoElement> GetElementsByJQuery(string jQuery)
		{
			JsVal jsValue;
			var elements = new List<GeckoElement>();

			using (var autoContext = new AutoJSContext())
			{
				autoContext.PushCompartmentScope((nsISupports)m_Window.Document.DomObject);
				jsValue = autoContext.EvaluateScript(jQuery);
				if (!jsValue.IsObject) 
					return elements;

				if (!SpiderMonkey.JS_HasProperty(autoContext.ContextPointer, jsValue.AsPtr, "length"))
				{
					return null;
				}

				var length = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, "length").ToInteger();
				if (length == 0)
				{
					return null;
				}

				for (var elementIndex = 0; elementIndex < length; elementIndex++)
				{
					var firstNativeDom = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, elementIndex.ToString(CultureInfo.InvariantCulture)).ToComObject(autoContext.ContextPointer);
					var element = Xpcom.QueryInterface<nsIDOMHTMLElement>(firstNativeDom);
					if (element != null)
					{
						elements.Add(GeckoHtmlElement.Create(element));
					}
				}
			}
			return elements;
		}
Esempio n. 2
0
        public void PushCompartmentScope_PushANewScopeObject_PeekNoLongerReturnsGlobalContext()
        {
            _browser.TestLoadHtml("hello world");
            using (var context = new AutoJSContext(_browser.Window.JSContext))
            {
                context.PushCompartmentScope((nsISupports)_browser.Window.DomWindow);

                var globalObject = SpiderMonkey.DefaultObjectForContextOrNull(context.ContextPointer);
                Assert.AreNotEqual(context.PeekCompartmentScope(), globalObject);
            }
        }
Esempio n. 3
0
        public JsVal ExecuteJQuery(string jQuery)
        {
            JsVal jsValue;

            using (var autoContext = new AutoJSContext())
            {
                autoContext.PushCompartmentScope((nsISupports)m_Window.DomWindow);
                jsValue = autoContext.EvaluateScript(jQuery);
            }

            return(jsValue);
        }
Esempio n. 4
0
		public JsVal ExecuteJQuery(string jQuery)
		{
			JsVal jsValue;

			using (var autoContext = new AutoJSContext())
			{
				autoContext.PushCompartmentScope((nsISupports)m_Window.DomWindow);
				jsValue = autoContext.EvaluateScript(jQuery);
			}

			return jsValue;
		}
Esempio n. 5
0
        public void FindInterfaceWithMember_OnAWindowElementLookingForNameMethod_ReturnsInterfaceThatContainsMethodNode()
        {
            _browser.TestLoadHtml("hello world");
            using (var context = new AutoJSContext(_browser.Window.JSContext))
            {
                context.PushCompartmentScope((nsISupports)_browser.Window.DomWindow);
                var jsValWindow = context.EvaluateScript("this");
                var jsVal       = SpiderMonkeyTests.CreateStringJsVal(context, "name");
                var jsObject    = SpiderMonkey.JS_ValueToObject(context.ContextPointer, jsValWindow);
                var a           = m_instance.GetWrappedNativeOfJSObject(context.ContextPointer, jsObject);

                // Perform the test.
                var i = a.FindInterfaceWithMember(ref jsVal.AsPtr);

                Assert.NotNull(i);
                Assert.IsTrue(i.IsScriptable());
                Assert.AreEqual("nsIDOMWindow", i.GetNameShared());
            }
        }
Esempio n. 6
0
		public GeckoElement GetElementByJQuery(string jQuery)
		{
			JsVal jsValue;

			using (var autoContext = new AutoJSContext())
			{
				autoContext.PushCompartmentScope((nsISupports)m_Window.Document.DomObject);
				jsValue = autoContext.EvaluateScript(jQuery);
				if (jsValue.IsObject)
				{					
					var nativeComObject = jsValue.ToComObject(autoContext.ContextPointer);
					var element = Xpcom.QueryInterface<nsIDOMHTMLElement>(nativeComObject);
					if (element != null)
					{
						return GeckoHtmlElement.Create(element);
					}

					if (!SpiderMonkey.JS_HasProperty(autoContext.ContextPointer, jsValue.AsPtr, "length"))
					{
						return null;
					}

					var length = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, "length").ToInteger();
					if (length == 0)
					{
						return null;
					}

					var firstNativeDom = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, "0").ToComObject(autoContext.ContextPointer);
					element = Xpcom.QueryInterface<nsIDOMHTMLElement>(firstNativeDom);
					if (element != null)
					{
						return GeckoHtmlElement.Create(element);
					}				
				}

			}
			return null;
		}
Esempio n. 7
0
        public GeckoElement GetElementByJQuery(string jQuery)
        {
            JsVal jsValue;

            using (var autoContext = new AutoJSContext())
            {
                autoContext.PushCompartmentScope((nsISupports)m_Window.Document.DomObject);
                jsValue = autoContext.EvaluateScript(jQuery);
                if (jsValue.IsObject)
                {
                    var nativeComObject = jsValue.ToComObject(autoContext.ContextPointer);
                    var element         = Xpcom.QueryInterface <nsIDOMHTMLElement>(nativeComObject);
                    if (element != null)
                    {
                        return(GeckoHtmlElement.Create(element));
                    }

                    if (!SpiderMonkey.JS_HasProperty(autoContext.ContextPointer, jsValue.AsPtr, "length"))
                    {
                        return(null);
                    }

                    var length = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, "length").ToInteger();
                    if (length == 0)
                    {
                        return(null);
                    }

                    var firstNativeDom = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, "0").ToComObject(autoContext.ContextPointer);
                    element = Xpcom.QueryInterface <nsIDOMHTMLElement>(firstNativeDom);
                    if (element != null)
                    {
                        return(GeckoHtmlElement.Create(element));
                    }
                }
            }
            return(null);
        }
Esempio n. 8
0
        public IEnumerable <GeckoElement> GetElementsByJQuery(string jQuery)
        {
            JsVal jsValue;
            var   elements = new List <GeckoElement>();

            using (var autoContext = new AutoJSContext())
            {
                autoContext.PushCompartmentScope((nsISupports)m_Window.Document.DomObject);
                jsValue = autoContext.EvaluateScript(jQuery);
                if (!jsValue.IsObject)
                {
                    return(elements);
                }

                if (!SpiderMonkey.JS_HasProperty(autoContext.ContextPointer, jsValue.AsPtr, "length"))
                {
                    return(null);
                }

                var length = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, "length").ToInteger();
                if (length == 0)
                {
                    return(null);
                }

                for (var elementIndex = 0; elementIndex < length; elementIndex++)
                {
                    var firstNativeDom = SpiderMonkey.JS_GetProperty(autoContext.ContextPointer, jsValue.AsPtr, elementIndex.ToString(CultureInfo.InvariantCulture)).ToComObject(autoContext.ContextPointer);
                    var element        = Xpcom.QueryInterface <nsIDOMHTMLElement>(firstNativeDom);
                    if (element != null)
                    {
                        elements.Add(GeckoHtmlElement.Create(element));
                    }
                }
            }
            return(elements);
        }