Closed
Bug 504635
Opened 15 years ago
Closed 15 years ago
[shared module] Need a helper function to extract entities from DTD files
Categories
(Mozilla QA Graveyard :: Mozmill Tests, defect)
Mozilla QA Graveyard
Mozmill Tests
Tracking
(Not tracked)
VERIFIED
FIXED
People
(Reporter: u279076, Assigned: adriank)
References
Details
(Whiteboard: [mozmill-doc-complete])
Attachments
(1 file, 3 obsolete files)
(deleted),
patch
|
whimboo
:
review+
|
Details | Diff | Splinter Review |
Currently, there is no easy way to extract an entity from a dtd file. This means that we cannot check localized strings.
This bug is a tracking bug for implementing a getEntity() method in UtilsAPI.
This blocks bug 504497 as I need to compare the tab title against the certerror.pagetitle entity in aboutCertError.dtd.
Blocks: 504497
Comment 2•15 years ago
|
||
Any idea how to do that? I know that this could be hard to do with JS but otherwise how we should check for correctness?
Component: Security → Mozmill
OS: Mac OS X → All
Product: Firefox → Testing
QA Contact: firefox → mozmill
Hardware: x86 → All
Summary: [mozmill] Need a way to extract entities from DTD files → Need a way to extract entities from DTD files
Version: Trunk → unspecified
Updated•15 years ago
|
Summary: Need a way to extract entities from DTD files → [shared-module] Need a helper function to extract entities from DTD files
Comment 3•15 years ago
|
||
One way to do it would be to create a data url for something like
<?xml version="1.0"?>
<!DOCTYPE elem [
<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >
%brandDTD;
]>
<elem>&brandShortName;</elem>
but that requires you to know all DTD chrome urls. I don't see a way to get those by DOM inspection of the generated document.
Comment 4•15 years ago
|
||
That's the way what Benjamin has proposed too. There is no need to know about all the DTD's inside this helper function. It will simply be a parameter which gets folded in like: getEntity(chromeURL, entityName).
Comment 5•15 years ago
|
||
Oh and we would have to open that data url in a hidden window to not cause a focus switch to another window.
Updated•15 years ago
|
Comment 6•15 years ago
|
||
You'll need a list of chromeURLs, as some DTDs reference others, in particular, brand.dtd. There are more, though.
And you won't need a window at all, using just DOMParser.parseFromString should do it.
Comment 7•15 years ago
|
||
Code snippet:
p = new DOMParser();
d=p.parseFromString('<?xml version="1.0"?><!DOCTYPE elem [<!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >%brandDTD;]><elem id="brandShortName">&brandShortName;</elem>','text/xml')
[object XMLDocument]
$('elem[id=brandShortName]',d).text()
Minefield
With the id stuff, you can actually get out multiple values in one document, if that's required.
Assignee | ||
Comment 8•15 years ago
|
||
A patch based on Pike's approach from Comment #7
Assignee: nobody → akalla
Attachment #439521 -
Flags: review?(hskupin)
Updated•15 years ago
|
Status: NEW → ASSIGNED
Summary: [shared-module] Need a helper function to extract entities from DTD files → [shared module] Need a helper function to extract entities from DTD files
Updated•15 years ago
|
Attachment #439521 -
Flags: review?(hskupin) → review+
Comment 9•15 years ago
|
||
Comment on attachment 439521 [details] [diff] [review]
patch based on Pike's approach
>+ * Called to get the value of an individual entity in a DTD file.
>+ *
>+ * @param {array} url
>+ * An array of string urls.
You should use [string] as the type so we also can see the parameter type. I would also prefer to have a better description which at least include that we have URLs to DTDs here.
>+function getEntity(urls, entityId)
>+{
>+ var entities = "";
>+ for (i = 0; i < urls.length; i++) {
>+ entities += '<!ENTITY % dtd' + i + ' SYSTEM "' + urls[i] + '">%dtd' + i + ';';
>+ }
Here we are building a string of external entities. Can you please reflect that in the variable name?
>+ var doc = parser.parseFromString(header + elem, 'text/xml');
>+ return doc.querySelector('elem[id="elementID"]').textContent;
>+}
Can you please add an empty line before the return statement and split this one into two lines? That would be better readable.
Also make sure that the new function matches the alphabetical order of all functions in that file.
With those changes, r=me.
Updated•15 years ago
|
Whiteboard: [mozmill-doc-needed]
Assignee | ||
Comment 10•15 years ago
|
||
taking r+ from previous patch
Attachment #439521 -
Attachment is obsolete: true
Attachment #441399 -
Flags: review+
Comment 11•15 years ago
|
||
Comment on attachment 441399 [details] [diff] [review]
patch v2
Adrian, what about the additional dtd, which should be included by default as what Axel has been proposed? That information arrived after I have reviewed your last patch.
Attachment #441399 -
Flags: review+
Assignee | ||
Comment 12•15 years ago
|
||
(In reply to comment #11)
> Adrian, what about the additional dtd, which should be included by default as
> what Axel has been proposed? That information arrived after I have reviewed
> your last patch.
Right, I forgot about it.
The question here is, if it should be included by default in the array, or if a comment about the possible necessity of including the xhtml11.dtd would be enough?
Comment 13•15 years ago
|
||
Can you please tell again why this dtd is needed? Given our short discussion via email it is not clear for me which purpose it has.
Comment 14•15 years ago
|
||
When loading an xhtml document, the parser silently add xhtml11.dtd to include the html pre-defined entities, like ä.
Some localizers use those in their dtd entities, and sometimes the code does. Like ®, for example.
Comment 15•15 years ago
|
||
Ok, given that we should always include this dtd. We shouldn't force the author to add it to the test itself.
Axel, the only downside for the general inclusion would be some milliseconds for parsing this DTD, right?
Comment 16•15 years ago
|
||
xhtml11.dtd is only included for xhtml docs, not for xul docs.
So "always" isn't strictly true.
But I doubt it'll be bad for the tests if it's always on.
Assignee | ||
Comment 17•15 years ago
|
||
based on previous comments, it looks like always adding the xhtml11.dtd is the best idea.
The only change in this patch in compare to the previous one is to add the xhtml11.dtd by default
Attachment #441399 -
Attachment is obsolete: true
Attachment #444210 -
Flags: review?(hskupin)
Comment 18•15 years ago
|
||
Comment on attachment 444210 [details] [diff] [review]
patch v3: add xhtml11.dtd by default
> /**
>+ * Called to get the value of an individual entity in a DTD file.
nit: Please use "Returns the value...". You can also update the heading of getProperty.
>+ var extEntities = "";
>+ // Build a string of external entities
>+ for (i = 0; i < urls.length; i++) {
nit: Move the comment before the variable declaration.
>+ extEntities += '<!ENTITY % dtd' + i + ' SYSTEM "' + urls[i] + '">%dtd' + i + ';';
nit: Try to limit it to 80 characters.
With those updates you will get the final r=me.
Attachment #444210 -
Flags: review?(hskupin) → review+
Assignee | ||
Comment 19•15 years ago
|
||
addressing review comments from Comment 18
Attachment #444210 -
Attachment is obsolete: true
Attachment #444270 -
Flags: review?(hskupin)
Comment 20•15 years ago
|
||
Comment on attachment 444270 [details] [diff] [review]
patch v4
+ extEntities += '<!ENTITY % dtd' + i + ' SYSTEM "' +
>+ urls[i] + '">%dtd' + i + ';';
>+ }
>+ var parser = Cc["@mozilla.org/xmlextras/domparser;1"]
The alignment of the wrapped line is not correct and an empty line is missing after the for loop. But I will fix that with the check-in.
Attachment #444270 -
Flags: review?(hskupin) → review+
Comment 21•15 years ago
|
||
Landed on all branches as:
http://hg.mozilla.org/qa/mozmill-tests/rev/38e5b63d2d4d
http://hg.mozilla.org/qa/mozmill-tests/rev/0baec063da46
http://hg.mozilla.org/qa/mozmill-tests/rev/bd25448c9312
Adrian, can you also please update the documentation for that new function?
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Comment 22•15 years ago
|
||
(In reply to comment #21)
> http://hg.mozilla.org/qa/mozmill-tests/rev/38e5b63d2d4d
Benjamin, as you can hopefully remember we talked about fetching entities from DTD files during our last all hands in December. Now we have checked-in a solution for Mozmill only. Could you have a look at the checked-in source and tell me if we wanna have that function in our core code? If yes, what's the best place for it? Should it only be a part of the Mochitest framework or do we wanna see it related to string bundles?
Updated•15 years ago
|
Comment 23•15 years ago
|
||
That's a question for Axel really, but I don't know of a reason why we'd want that in our code now. l20n basically solves the entire issue, as I understand it.
Comment 24•15 years ago
|
||
(In reply to comment #23)
> That's a question for Axel really, but I don't know of a reason why we'd want
> that in our code now. l20n basically solves the entire issue, as I understand
> it.
You mentioned that to me in our talk. But if that's not the case anymore I'm fine with it. That will give Mozmill, compared to other existing frameworks, the unique feature to run tests against localized builds.
Assignee | ||
Comment 25•15 years ago
|
||
(In reply to comment #21)
> Adrian, can you also please update the documentation for that new function?
Done ( https://developer.mozilla.org/en/Mozmill_Tests/Shared_Modules/UtilsAPI )
Status: RESOLVED → VERIFIED
Assignee | ||
Updated•15 years ago
|
Whiteboard: [mozmill-doc-needed] → [mozmill-doc-complete]
Comment 26•14 years ago
|
||
Mass move of Mozmill Test related project bugs to newly created components. You can filter out those emails by using "Mozmill-Tests-to-MozillaQA" as criteria.
Component: Mozmill → Mozmill Tests
Product: Testing → Mozilla QA
QA Contact: mozmill → mozmill-tests
Updated•5 years ago
|
Product: Mozilla QA → Mozilla QA Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•